Using NVM to have multiple versions of Node on your machine.
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.
Note: If you do not have (or have never had) Node installed on your machine, jump to step 5.
- 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
- 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
+-- [email protected]
`-- [email protected]
-
Uninstall Node.js from your system (using Windows’ Add or remove programs).
-
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"
-
Download and install the nvm-setup.zip file from the latest release of NVM Windows. Accept all default options in the installer
-
Configure NVM (see official usage docs for more commands)
- Open Cmd as administrator
nvm install <node version>
- install the version of node you wantnvm 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
- 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.