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 Node.js version or multiple Node.js versions on the same system using nvm and use required version for application. This tutorial will help you to Install and Manage 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 – NVM Installation
First of all, 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.
source ~/.profile ## Debian based systems source ~/.bashrc ## CentOS/RHEL systems
Step 2 – Find Available Node.js Version
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.
You will see a long list of available versions.
... ... v8.9.2 (LTS: Carbon) v8.9.3 (LTS: Carbon) v8.9.4 (LTS: Carbon) v8.10.0 (Latest LTS: Carbon) v9.0.0 v9.1.0 ... v9.6.1 v9.7.0 v9.7.1
Step 3 – Node.js Installation with NVM
Now install the node.js version you need to use for running node.js application. Below command will install node.js v8.10.0 the LTS release on your system.
nvm install v8.10.0
You can have also installed the latest version of Node.js.
nvm install v9.7.1
Repeat the above command with the different-2 node.js versions to install multiple versions of node.js on your system.
Step 4 – Set Node.js Default 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.
nvm listv6.11.5 v8.10.0 -> v9.7.1 default -> v6.11.5 node -> stable (-> v9.7.1) (default) stable -> 9.7 (-> v9.7.1) (default) iojs -> N/A (default) lts/* -> lts/carbon (-> v8.10.0) lts/argon -> v4.8.7 (-> N/A) lts/boron -> v6.13.1 (-> N/A) lts/carbon -> v8.10.0
You can see that Node.js version 9.4.0 is set as the default version. You can change the default Node.js version. Below command will set 8.9.4 as default Node.js version.
nvm use v8.10.0
Now verify current active version of node.js
node --version v8.10.0
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
nvm run v8.10.0 app.js
Step 6 – Remove Unused Node.js Version
This command will provide a list of installed versions of node.js on your system.
Now remove any version installed on your system using the following command. Below command will remove Node.js version v6.11.5 from your system.
nvm remove v6.11.5