Skip to content

Instantly share code, notes, and snippets.

@Dobby89
Last active February 15, 2022 11:29
Show Gist options
  • Save Dobby89/794cdc137ccff4dd72e6712ef49e4960 to your computer and use it in GitHub Desktop.
Save Dobby89/794cdc137ccff4dd72e6712ef49e4960 to your computer and use it in GitHub Desktop.
How to install Node on your Windows computer

How (best) to Install Node on Windows

Using NVM to have multiple versions of Node on your machine.

Background

You might have multiple projects on your system, which can all potentially require different and very specific versions of Node.js to run.

In order to make sure we can develop each project locally, we need to be able to set which versions of Node our machines are using for that particular project.

Instructions

Note: If you do not have (or have never had) Node installed on your machine, jump to step 5.

  1. Run the following command in your terminal and make note of the version of node you currently have installed:
node -v

Example output

$ node -v
v12.18.2

  1. Run the following command and make note of all the global node packages you have installed as you will want to reinstall these later:
npm list -g --depth 0

Example output

$ npm list -g --depth 0
+-- rimraf@3.0.2
`-- serverless@2.41.2

  1. Uninstall Node.js from your system (using Windows’ Add or remove programs).

  2. Open the Windows Command Prompt as administrator (right click -> Run as administrator) and remove any leftover artefacts from Node.js which the uninstaller didn’t remove.

important: Make sure you replace <user> with your username.

mkdir "C:\Program Files\emptyDir" && robocopy "C:\Program Files\emptyDir" "C:\Program Files\nodejs" /purge && robocopy "C:\Program Files\emptyDir" "C:\Users\<user>\AppData\Roaming\npm" /purge && rmdir "C:\Program Files\emptyDir" && rmdir "C:\Program Files\nodejs" && rmdir "C:\Users\<user>\AppData\Roaming\npm"
  1. Download and install the nvm-setup.zip file from the latest release of NVM Windows. Accept all default options in the installer

  2. Configure NVM (see official usage docs for more commands)

  • Open Cmd as administrator
    • nvm install <node version> - install the version of node you want
    • nvm use 10.15.0 - set which version of Node you wish to use:
    • nvm list - check to see which versions of Node are installed and which version your system is currently using:

You should see something like the following:

14.15.1
* 12.18.2 (Currently using 64-bit executable)
10.15.0
8.11.3

  1. If re-installing Node, install all the global Node modules you made a note of in step 2 as you normally would with Node, using:
npm install -g <package-name>

Important: Global Node packages need to be installed for each version of Node you are using as outlined here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment