
Consider that you have multiple NVM projects. One of them dependents on node v14, and one of them dependents on node v16. How to switch different versions of nodes?
What is NVM?
NVM, Node Version Manager, allows you to quickly install and use different versions of Node via the command line. You can see the NVM project on https://github.com/nvm-sh/nvm
Install NVM on Linux
It is not difficult to install nvm on Linux. You can see instructions on https://github.com/nvm-sh/nvm#install--update-script.
At the beginning, download NVM and run the shell script by curl
or wget
.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
The above script will set environment variables automatically in ~/.bashrc
. However, we should restart the terminal to apply new environment variables or instead use source ~/.bashrc
.
source ~/.bashrc
If you do not know what is barshrc, I found some pages that introduces bashrc.
- English: https://www.journaldev.com/41479/bashrc-file-in-linux
- Chinese: https://www.itread01.com/content/1542833526.html
Install NVM on Windows
NVM does not supports Windows but there is a similar tool called nvm-windows
.
- Download installation executable file. https://github.com/coreybutler/nvm-windows/releases
- Install.
- Restart command line.
- After installation. Type
nvm version
to check. If command line still can not find the path of nvm, please set environment variable manually .

In my opinion, do not install NVM by chocolatey directly, because the version of nvm-windows on chocolatey is out of date. The new version of node.js is not supported by the older nvm-windows.
Install Node by NVM.
Instead of installing different NVM by yum
or apt-install
, in my experience, I recommend that install Node.js by NVM.
For example, if you want to install Node.js v16.14.2
nvm install 16.14.2
Besides, you can list all versions of Node.js on your environment by nvm list
nvm list


Switch difference versions of Node by NVM
After listing all the versions of Nodes. You can use one of them by nvm use
For example, if we have 3 versions of nodes
- Node v17.5.0
- Node v16.6.1
- Node v14.17.13
We can switch to v16.6.1 by nvm use 16.6.1
or just nvm use 16
