How To Install Node.js on a CentOS 7 Server

Install Node JS on CentOS

You can get simple and understandable steps to Install Node.js on CentOS 7. Before we move into the installation, let’s have a brief look on Node.js.

What is this Node.js?

Let me tell you. Node.js  is an open-source tool. In the Server, Java-script is used in Node.js. Node.js can be used on multiple platforms like Windows, Linux, Unix, Mac OS X, etc., It is designed to build scalable network applications. it can be used to develop scalable systems, because of its non-blocking feature. Node.js is an efficient and easy than a traditional web server model.

What is this CentOS?

CentOS is a Community Enterprise Operating System. It is an open-source platform for non-productive developmental work. For production concern, those works can be migrated to RHEL (Payable) Linux distribution platform.

Let’s have a quick look on Node.js features and versions available!!!

A common web server will work on sequential four steps like sending a task to file system, then the file system has to open and read the file, then return the content and finally server starts the next request. In Node.js, once the task is sent to the file system, Node.js is ready to handle the next request. This feature avoids the waiting and response time from the file system. This provides the asynchronous programming feature to Node.js.

Node.js won’t run any function on I/O directly, this enables the non-blocking feature in Node.js. It has a single thread based Networking system. It can generate dynamic page content. Node.js was very much Memory Efficient.

Here’s the important Version list of Node.js  -> Node.js 12.13.0, Node.js 12.12.0, Node.js 12.11.1, Node.js 12.11.0, Node.js 12.10.0, Node.js 12.9.1, Node.js 12.9.0, Node.js 12.x.x, Node.js 10.x, Node.js 8.x, Node.js 6.x, Node.js 4.x, Node.js 0.12.x, Node.js 0.10.x

Before Installation

Before we start,

Apache Web Server  – We need to install apache! Check out our article Install Apache on CentOS 7.
PHP  – Then we need to install PHP! Check out our article Install PHP on CentOS.
MySQL  – Then we need to install MySQL! Check out our article Install MySQL on CentOS 7.

Install Node.js on CentOS 7

Yeah We are ready to start the installation of Node.js on CentOS . Let’s Go.


1) VM Setup:

The first step is to log-in to your Google Cloud account and then we need to select the option “Compute Engine” on the menu.

Now we can see “VM instances” in Compute Engine. Click on that as shown in the below image.

Google Cloud VM Instances
Google Cloud VM Instances

As shown in the image, in the right end you can select “open in browser window”.

Now we can see the terminal and we are now ready to execute the below commands step by step.


2) Adding the Yum Repository:

What is a Yum Repository? YUM (Yellowdog Updater Modified) is an open-source command-line that creates, maintains, updates, removes and manages a high-quality set of packages on CentOS.

yum install -y gcc-c++ make

3) Build native add-ons:

Now we are done with Yum repository. To install Node.js from the Node Source YUM repository, We need to execute the below commands (anyone). Also to install native add-ons from NPM We will install a compiler.

A) The latest version of Node.js

curl -sL https://rpm.nodesource.com/setup_12.x | sudo -E bash –

B) The stable version of Node.js

curl -sL https://rpm.nodesource.com/setup_10.x | sudo -E bash –

The basic difference between the latest and stable versions is limitations and bugs. The stable version was tested and fixes will be available. In latest version, it might have some fix but also additional features.


4) Install Node.js:

Now are having the packages of Node.js and NPM. We can install the Node.js package using the following command. By executing below command, Node.js and NPM packages both will get install.

sudo yum install nodejs

After installation of Node.js


1) Testing Node.js:

To check the installation of Node.js, we need to execute the below command. This will display you the version we installed.

node -v

2) Testing NPM:

To check the installation of NPM, we need to execute the below command. This will display you the version of NPM we installed.

npm -v
You could able to launch your own Node.js web server now. 😀

Web Server Creation (Example)


1) Create File:

First, we need a file to do our programming of servers. Create a file with .js as an extension. Use the following command to create the file.

vim demo_server.js

2) Do programming:

Let’s create a small server program file with the basic function. You can put on the below content in the file we created.


3) Execute the file:

Now we can execute the file, that we created on Node.js using the following command,

node –inspect demo_server.js

Now you can access the web server, using the URL that we got during the programming.

Here you go…!! We successfully installed and programmed the Node.js on CentOS.

You can now start working on Node.js  !!  

Today, we learned about “What is Node.js”, “Basics of Node.js and CentOS” , “Features and Versions available in Node.js”, “Steps to be followed before installing Node.js ”, “How to install Node.js in CentOS?” , “Install Node.js on CentOS 7”,“Steps to be followed after installing Node.js” and finally “How to validated and create a web server in Node.js”.

I hope it helped you in an easy way to install Node.js with more understanding. Please let us know in the comment section if you have any concerns.

You can also share with your friends, who need to install Node.js. Will meet you in my upcoming articles. Bye for now.