How to install Node.js and NPM on CentOS?

Install Node.js on CentOS

Install Node.js and NPM on CentOS:

  1. Adding node.js yum repository to the system
  2. Installing node.js and NPM
  3. Verifying the versions
  4. Installation test of Node.js

What is Node.js?

Node.js is a cross-platform JavaScript run-time environment that allows the execution of JavaScript code from the server-side.

However, the majority uses the Node.js on the back-end; it is also popular as a full-stack and front-end solution.

Node Package Manager or NPM is the default package manager for Node.js. It is a vast software repository for the open-source Node.js packages.

In this article, we are going to install the Node.js and NPM on CentOS 7.

We will be installing Node.js and npm using the yum package manager from the NodeSource repository.

1. Adding Node.js yum repository to the system

First, we have to add yum repository of Node.js to the system. The repository is maintained by NodeSource, which is a company working to providing enterprise-grade Node support.

Run the following commands to add the yum repository:

# yum install -y gcc-c++ make
# curl -sL | sudo -E bash -

The v12 is the latest LTS version of Node.js. You can change the setup version by changing the version in the command.

2. Install Node.js and NPM

You can install the node.js package and NPM package with a single command.

Not only node.js and NPM packages, but this command will install the other packages that are required.

Use the following command:

yum install nodejs

3. Verifying the Version

After installing the Node.js on the CentOS 7, you have to verify if the installed version is correct.

To check the Node.js version:

node -v 

To check the NPM version:

npm -v

4. Installation test

In the end, we will test the installation of the Node.js on the CentOS.

For that create a test file with this command:

vim test_server.js

Add this content to the file:

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

Start the WebServer with this command

node --debug test_server.js
debugger listening on port 5858
Server running at

The WebServer will restart, and you would be able to access it on

Alternative: Install Node.js from the EPEL Repository

An alternative method to install Node.js and NPM is by using EPEL Repository (Extra Packages for Enterprise Linux).

Modify your repo-list of installation to get access to the EPEL repository. You can do this by reconfiguring the access to the repository by installing a package available in the repos called epel-release.

Use the following command:

sudo yum install epel-release

After gaining access to the EPEL repository, the installation of the Node.js can be done with the help of yum command.

sudo yum install nodejs

Finally, check the version of the Node.js with the command:

node --version

If you want the NPM to manage the Node.js, use the following command to install the NPM.

sudo yum install npm

Wrap Up

In this article, we installed Node.js and NPM on CentOS 7 using the commands.

There are various ways to install Node.js and NPM to the CentOS, though I only mention two that are the simplest among all.

If you still any doubt regarding how to install Node.js, do tell us in the comment section.

Latest Magento Tips, Guides, & News

Stay updated with new stuff in the Magento ecosystem including exclusive deals, how-to articles, new modules, and more. 100% Magento Goodness, a promise!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top

We can help you. Right now.

Fast growing merchants depend ServerGuy for high-performance hosting. Experience counts. Let's get started.

Talk to a sales representative

USA / Worldwide




Core Web Vitals Book COver

Is your website ready for Core Web Vitals?

Take this FREE book with you and optimize your store for speed.

Learn all about new Google new ranking factors and get that top ranking.