NVM is known as Node Version Manager, Similarily to RVM (Ruby Version Manager) for Ruby language. NVM provides an option for the easy installation of Node.js. You can also install a specific Node.js version or multiple Node.js versions on the same system using nvm and use the required version for the 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 – Install NVM
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.
... ... v12.14.0 (LTS: Erbium) v12.14.1 (LTS: Erbium) v12.15.0 (LTS: Erbium) v12.16.0 (LTS: Erbium) v12.16.1 (LTS: Erbium) v12.16.2 (Latest LTS: Erbium) ... ... v13.11.0 v13.12.0 v13.13.0 v14.0.0
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 12.16.2 the LTS release on your system.
nvm install v12.16.2
You can have also installed the latest version of Node.js.
nvm install v14.0.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 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 list v4.9.1 v6.17.1 v8.17.0 v10.16.0 v10.20.1 -> v12.16.2 v14.0.0 default -> v12.16.2 node -> stable (-> v14.0.0) (default) stable -> 14.0 (-> v14.0.0) (default) iojs -> N/A (default) unstable -> N/A (default) lts/* -> lts/erbium (-> v12.16.2) lts/argon -> v4.9.1 lts/boron -> v6.17.1 lts/carbon -> v8.17.0 lts/dubnium -> v10.20.1 lts/erbium -> v12.16.2
You can see that Node.js version v12.13.1 is set as the default version. You can change the default Node.js version. The below command will set 12.13.1 as default Node.js version.
nvm use v12.16.2
Now verify current active version of node.js
node --version v12.13.1
Step 5 – Run Application 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 a node.js version for running any application. For example
nvm run v12.16.2 app.js
Step 6 – Remove Unused Node.js Version
This command will provide a list of installed versions of node.js on your system.
You can remove any unused version from your system. Use the following nvm command to remove Node.js version 4.9.1 from your system.
nvm uninstall v4.9.1