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 install specific nodejs version or multiple nodejs versions 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 .
The default NVM installs under current users home directory, So nvm installation with one user will not be accessible to another user. Windows users can visit our other tutorial to install Nodejs on Windows system.
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 [email protected]:~#source ~/.bashrc #For CentOS/RHEL Systems
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 (LTS: Boron) v6.11.1 (Latest LTS: Boron) ... ... v7.10.1 v8.0.0 v8.1.0 v8.1.1 v8.1.2 v8.1.3 v8.1.4 v8.2.0 v8.2.1
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.1 the LTS release on your system.
[email protected]:~#nvm install 6.11.1
You can have also installed the latest version of Node.js.
[email protected]:~#nvm install 8.2.1
Repeat the above command with the different-2 node.js versions to install multiple versions of node.js on your system.
Step 4 – Use Installed 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. Use below command to list currently installed version and default set version.
[email protected]:~#nvm list v6.11.1 -> v8.2.1 default -> 6.11.1 (-> v6.11.1) node -> stable (-> v8.2.1) (default) stable -> 8.2 (-> v8.2.1) (default)
As you can see that Nodejs 8.2.1 is set to default version. Now if required to set other version as default, use following command.
[email protected]:~#nvm use 6.11.1
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.1 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.1 from your system. Change 6.11.1 with the specific version you want to remove from the system.
[email protected]:~#nvm remove 6.11.1