How To Install and Manage Node.js with NVM. NVM is known as Node Version Manager. Like RVM (Ruby Version Manager) NVM provides an option for easy installation of Node.js. You can also installed multiple versions of nodejs on same system using nvm.
1. Install 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/v0.33.0/install.sh | bash
Reload system environment using this command. It will set the required environment variables to use nvm on the system.
# source ~/.profile
2. Install Node.js
This command will list all the available version of node.js to be installed and highlight the version your are currently using.
# nvm ls-remote
Now install required version of node.js. Below command will install node.js 6.9.5 LTS on your system.
# nvm install 6.9.5
Repeat the above command with the different-2 node.js version to install multiple versions of node.js.
3. Set Default Node.js Version
Now use below command to select the specific version of node.js to load in the environment.
# nvm use 6.9.5
Now verify current active version of node.js
# node --version
4. Run App 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 6.9.5 app.js
5. Remove Node.js
This command will provide a list of installed versions of node.js on your system.
# nvm list
Below command will delete node.js 6.9.5 from your system. Change 6.9.5 with the specific version you want to remove from the system.
# nvm remove 6.9.5