Manage Node.js Version by NVM

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

Install NVM on Linux

It is not difficult to install nvm on Linux. You can see instructions on

At the beginning, download NVM and run the shell script by curl or wget.

curl -o- | bash


wget -qO- | 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.

  1. English:
  2. Chinese:

Install NVM on Windows

NVM does not supports Windows but there is a similar tool called nvm-windows .

  1. Download installation executable file.
  2. Install.
  3. Restart command line.
  4. After installation. Type nvm version to check. If command line still can not find the path of nvm, please set environment variable manually .
See NVM’s version.

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
nvm list on windows 11
nvm list on Ubuntu 18

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

  1. Node v17.5.0
  2. Node v16.6.1
  3. Node v14.17.13

We can switch to v16.6.1 by nvm use 16.6.1 or just nvm use 16

Notice that I installed gsudo on my Windows. If you do not install gsudo in advance, please run the command on the administrative mode.





Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


A person who loves computer science shares implementations. Github: @liao2000