How to install Multiple Versions of Node Using nvm

Table of Content

nvm

Keep up with the latest technology and frameworks is hard, specially If you are into the JavaScript/Node environment and surrounded technology, not to mention about the npm and the version incompatibility issues. I've been working lately on create ionic starters to help developers to have an starting point to create ionic applications faster. You can find the starters on the ionic market, here's a list in case you are interested:
https://market.ionicframework.com/starters/ionappfull4pro
https://market.ionicframework.com/starters/ionpushempro
https://market.ionicframework.com/starters/ionshopping
https://market.ionicframework.com/starters/ionrestaurant

Keep up with ionic and packages versions

Ionic is a great technology, you can create multi-platform app with one code base, create PWAs, etc. The problem is when you try to use/run an ionic app made in another environment (using different node version, etc.) on your recently created environment (latest Node.js version), one of the most commons issues is related to the installed Node.js version of the user that are trying to make the code run. This is not only valid to ionic, but to any code that relays on Node.

Lets install the same Node version used to create the original code, and problem solved?

You can certainly do that, and if that's your case, that's it, you are done, problem solved, but what happen if you have more than one Node projects on your computer, that could need to use older versions of node, this is a very common scenario for people that works heavily with different projects and different package versions.

nvm to the rescue

It stands for Node Version Manager. As the name suggests, it helps you manage and switch between different Node versions with ease. It provides a command line interface where you can install different versions with a single command, set a default, switch between them and much more.

Installation

I'm going to focus on windows for this article, if you have a different OS, you can find information on it's official github repo https://github.com/creationix/nvm.

First, make sure you uninstall any Node.js version you might have on your system, as they can collide with the installation. After this, download the latest stable installer here. Run the executable installer, follow the steps provided and you’re good to go!

Installing multiple Node.js Versions

If installed correctly, the nvm command is available anywhere in you terminal. You can run nvm -v command in your terminal to make sure, a list with the help instructions should show.

Managing, installing and switching Node.js versions

To install the latest Node.js version, you can just run:

nvm install node

To install specific version:

nvm install 8.9.4

If you want to install, for example, the latest 8.9 patch, it will then install Node.js version 8.9.X, where X is the highest available version, you can do it by running the following command:

nvm install 8.9

To see the full list of available versions:

nvm ls

You can also uninstall any instance you no longer think is useful, by running:

nvm uninstall 8.9.4

Switching between Versions

To switch through installed versions, nvm provides the nvm use command. This works similar to the install command. So, you need to follow this by a version number, for example:
switch to Node.js version 8.9.4:

nvm use 8.9.4

switch to Node.js version 9.3.0:

nvm use 9.3

switch to latest Node.js version

nvm use node

As you can see it is super easy, hope this helps you.

Cheers