In this article, we will discuss two different ways for the installation of NodeJS on CentOS 8 distribution through the command line. The NodeJS along with npm can install on your CentOS 8 system by using the following two methods:
- Install NodeJS using the CentOS 8 repository
- Install NodeJS using the NVM
Method 1: Install NodeJS using the CentOS 8 repository
The NodeJS modules can be installed directly from the official CentOS 8 repository. While we are writing this tutorial, the latest available version of NodeJS is v10.x.
Use the following command to list the modules that contain the NodeJS packages:
$ sudo yum module list nodejs
The following output displays on the terminal that means the NodeJS package is available with multiple streams.
There are four different profiles of the NodeJS package. The one marked with [d] is a default profile, it installs a set of common runtime packages. However, use the following command to install the Nodejs package on CentOS 8 system:
$ sudo yum module install nodejs
The above-mentioned command also installs the required NPM modules after, pressing the ‘y’ and then ‘Enter’ key.
The other Nodejs profile is the development profile, which installs some additional packages that are necessary to build the loadable modules dynamically. Use the following command to install a development profile of NodeJS:
$ sudo yum module install nodejs/development
Once the NodeJS installation is completed, type the following command to check the installed version:
$ node --version
From the following screenshot, here, you can see that NodeJS version 10.24.0 has been installed on the CentOS 8 system.
The above-explained method is a sufficient and easiest way for the NodeJS and npm installation on CentOS 8.
Install required NodeJS Development Tools
The development tools are required for compiling and installing the add-ons from the npm registry. So, install the all necessary development tools by running the following command:
$ sudo dnf groupinstall 'Development Tools'
Press ‘y’ and then ‘Enter’ to install all necessary development packages.
Remove or Uninstall the NodeJS
Use the following command, to remove or uninstall the NodeJS and npm modules from your CentOS 8 system:
$ sudo yum module remove nodejs
Method 2: Install NodeJS using the NVM
Using the NVM (Node Version Manager) bash script, you can install and manage the NodeJS version on need. The NVM allows you to install or remove any NodeJS version from your CentOS 8 system that you want to test or use. So, use the following script to install the NVM on your CentOS 8 system:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
The above installation script clones the NVM repository from Github to the ~/.nvm directory and exports the nvm path to your Bash_profile.
To install the NodeJS using the nvm script, either, execute the commands that are printed on your terminal’s window or open a new shell session. After that, use the following command to install the nodejs stable version:
$ nvm install node
In the next step, install the latest version of NodeJS using the NVM by running the below-mentioned command:
$ nvm install –lts
Once the NodeJS is installed on your CentOS 8 system, list the all installed versions of NodeJS by executing the following command:
$ nvm ls
The default version v15.12.0 is currently using on this system, but, you can also change this version and use another NodeJS version by using the following command:
$ nvm use v14.16.0
To change the default version to another, use the following command:
$ nvm alias default v12.13.0
We have elaborated on two different methods in this article for the installation of NodeJS on the CentOS 8 system. Now, you can choose any one of both based on your preferences. Now, NodeJS is installed on your CentOS 8 system, you can deploy a NodeJS application on the system.