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. 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. 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. 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 usernvm ls To list all the available version’s for the installation on your system.nvm ls-remote Switch to other installed node version for the current session. The new version will be the default version for current shell onlynvm 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:
Conclusion
In this tutorial, you have learned to install nvm and node on CentOS 8 Linux system.