Manage multiple Node.js versions using NVM

Recently in one of my project, I couldn’t run the npm install command successfully. After debugging for a while I came to know that I needed previous version of Node.js to install all the dependency successfully.

One can face this kind of situation while developing Node.js applications or when you want to deploy the app which should be compatible with different Node versions.

NVM

NVM stands for Node Version Manager. It allow us to install multiple version of the Node.js and manage them. It provides command line interface where you can install different version of Node js and manage them. We can choose whichever version of the Node.js we want and go back to the default once we are done with it.

Install NVM

To read the installation steps for different OS please go to the NVM page on Github. There is also a Github page to install NVM on windows machines.

Using NVM

To install the latest version of the Node.js:

nvm install node

This will install the latest version of the Node.js.

To install the specific version of the Node.js, for example, if you want to install 0.11.14 version of the Node.js, do this:

nvm install 0.11.14

Above command will also install the compatible npm version as well. After installation finished, you need to point NVM to use 0.11.14 version of Node.js like below:

nvm use 0.11.14

To see all the installed version:

nvm list

This will list all the installed version like below image:

List of Node.js versions
List of Node.js versions

When you’re done with specific version and do not need it any more, you can uninstall it:

nvm uninstall 0.11.14

You can also set an alias to a specific Node version, if you want. Let’s say if you are working on a project named xyz which requires 0.11.14 node version.

nvm alias xyz 0.11.14

So whenever you are switching to xyz project you can switch Node version by using alias name and don’t need to remember the Node version.

nvm use xyz

You can also unset the alias:

nvm unalias xyz

Hope this helps!
NVM can be life saviour when you work on multiple projects parallel.

Web/ UI & Front-end developer based in Ahmedabad, GJ, India. Here to help/ discuss community to spread web awareness.

Leave a reply:

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.