NVM is known as Node Version Manager, Similarily to RVM (Ruby Version Manager) for Ruby language. NVM provides an option for easy installation of Node.js. You can also installed multiple versions of nodejs on the same system using nvm and use required version for application. This tutorial will help you to Install and Manage Multiple Node.js using NVM .
Note: By default, NVM install under current users home directory, So nvm installation with one user will not be accessible to another user.
Step 1 – Installing NVM
First, you need to install NVM on your system. A bash script is available to install nvm on your system. Use the following command to install NVM on your Linux system.
$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Reload system environment using this command. It will set the required environment variables to use nvm on the system.
[email protected]:~#source ~/.profile
Step 2 – List Available Node.js Versions
At this point, you have installed nvm on your system for the current user. Now find out the available version of Node.js to install. Use
ls-remote option to list versions.
[email protected]:~#nvm ls-remote
You will see a long list of available versions.
... v6.10.0 (LTS: Boron) v6.10.1 (LTS: Boron) v6.10.2 (LTS: Boron) v6.10.3 (LTS: Boron) v6.11.0
(Latest LTS: Boron)v7.0.0 v7.1.0 v7.2.0 v7.2.1 v7.3.0 v7.4.0 v7.5.0 v7.6.0 v7.7.0 v7.7.1 v7.7.2 v7.7.3 v7.7.4 v7.8.0 v7.9.0 v7.10.0 v8.0.0 v8.1.0
Step 3 – Installing Node.js
Now install the node.js version you need to use for running node.js application. Below command will install node.js 6.11.0 the LTS release on your system.
[email protected]:~#nvm install 6.11.0
You can have also installed the latest version of Node.js.
[email protected]:~#nvm install 8.1.0
Repeat the above command with the different-2 node.js versions to install multiple versions of node.js on your system.
Step 4 – Set Default Node.js Version
As you have installed multiple node.js versions, You can select the specific version of node.js as default version used by system and load in the environment.
[email protected]:~#nvm use 6.11.0
Now verify current active version of node.js
[email protected]:~#node --version
Step 5 – Run Applition with Specific Version
If you have multiple node.js applications on your system and want to run each with a specific version of node.js. NVM provides you an option to use node.js version for running any application. For example
[email protected]:~#nvm run 6.11.0 index.js
Step 6 – Remove Node.js
This command will provide a list of installed versions of node.js on your system.
[email protected]:~#nvm list
Below command will delete node.js 6.11.0 from your system. Change 6.11.0 with the specific version you want to remove from the system.
[email protected]:~#nvm remove 6.11.0