Written by , Updated on December 31, 2019

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Latest version node.js yum repository is maintaining by its official website. Use this tutorial to add yum repository and install Latest Nodejs to CentOS/RHEL 8 systems with the simple commands.

To install specific nodejs version, Visit our tutorial Install Specific Nodejs Version with NVM.

Step 1 – Add Node.js Yum Repository

First of all, You need to enable node.js yum repository in your system provided by the Node.js official website. You also need development tools to build native add-ons to be installed on your system.

For Latest Release:-

yum install -y gcc-c   make
curl -sL https://rpm.nodesource.com/setup_13.x | sudo -E bash -

For Stable Release:-

yum install -y gcc-c   make
curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash -

Step 2 – Install Node.js on CentOS 8

After adding a yum repository in your system lets install the Node.js package. NPM will also be installed with node.js. First, install some required packages on your system then download the Node.js rpm on your system for installation:

sudo dnf install -y python2 dnf-utils
sudo yumdownloader nodejs --disablerepo=AppStream

The above command will download Nodejs rpm package on your system. In my case, the package is nodejs-13.5.0-1nodesource.x86_64.rpm. You may newer packages of Node.js. So install see the current directory for the latest packages downloaded. Then install the package with the following command.

sudo rpm -ivh --nodeps nodejs-13.5.0-1nodesource.x86_64.rpm

Step 3 – Check Node.js and NPM Version

After installing node.js verify and check the installed version. You can find more details about current version on node.js official website.

node -v 

v13.5.0

Also, check the version of npm.

npm -v 

6.13.4

You have successfully installed Node.js on your CentOS 7 system. You may try a demo http server as given below.

Step 4 – Create Demo Web Server (Optional)

This is an optional step. If you want to test your node.js install. Let’s create a web server with “Welcome Node.js” text. Create a file demo_server.js

vim demo_server.js

and add the following content

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Welcome Node.js');
}).listen(3001, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3001/');

Now start the webserver using the command.

node --inspect demo_server.js

Debugger listening on ws://127.0.0.1:9229/9e0c7b4a-2ffe-48df-a4b0-b4635dcd9359
For help, see: https://nodejs.org/en/docs/inspector
Server running at http://127.0.0.1:3001/

Web server has been started on port 3001. Now access http://127.0.0.1:3001/ url in browser.