NVM stands for Node Version Manager is a command-line utility for managing Node versions. Sometimes you required to deploy multiple node application with different-2 versions. Nvm will help you here.
Why NVM ?
Node Version Manager has multiple benefits, Like:
- Use nvm to install multiple node versions on single system. Also switch node version any time with single command
- It allowed users to install any specific node version instead of latest version.
- The node installed using nvm is for specific user. It create .nvm directory under user home directory and keep everythink inside it
Installing NVM on CentOS 8
A shell script is available for the installation of nvm on the CentOS 8 or RHEL 8 Linux system. Open a terminal on your system or connect a remote system using SSH. Use the following commands to install curl on your system, then run the nvm installer script.
sudo dnf install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
This creates a .nvm directory under the home directory. Where nvm keeps own binary file and all other required files. Then it sets environment in users .bashrc file. You need to load this environment to set required configuration by running the following command:
Installing Node with NVM
Nvm allows to install multiple node versions on a single system or the logged in user. Execute below command to view a list of available node versions.
Then, install the required node version using the following command.
nvm install 12.19.0
Here you change 12.19.0 with your required version like 11.15.0, 10.11.0, etc.
It also provided alias for the latest stable node version, LTS version and other previous LTS version.
nvm install node
# Install latest stable version
nvm install lts/*
# Install latest lts version
You can also use lts/dubnium, lts/carbon etc to install other nodejs LTS versions.
Working with NVM
Here is some frequently used commands with nvm:
- List all the installed node versions for the current user
- To list all the available version’s for the installation on your system.
- Switch to other installed node version for the current session. The new version will be the default version for current shell only
nvm use 12.19.0
- Find the default Node version set for the current user, type:
nvm run default --version
- Run a script file with specific node version using exec option. This will not change the shell version.
nvm exec 12.19.0 server.js
Uninstall Specific Node Version with NVM
You can remove any unused version by running the following command. Just make sure the version you are removing is not currently active version.
To remove node.js 5.9.0 from your account, type:
nvm uninstall 5.9.0
In this tutorial, you have learned to install nvm and node on CentOS 8 Linux system.