How to Install Node.js on Centos 7

In this article, we want to teach you How to install Node.js on Centos 7. Before starting to learn, let’s see what Node.js is.

What is Node.js?

Node.js is an event-driven JavaScript runtime. Node has myriad potential uses for JavaScript development including being a great environment for building efficient network applications.

How to Install Node.js on Centos 7

There are different ways to install Node.js on Centos 7. In this article, we teach you to install Node.js in four ways.

1)Install Node from the Epel-repository

2)Install Node from the source

3)Install a package from the Node site

4)Install Node using the Node version manager

Note: You need to log in as a non-root user with Sudo privileges. you can check our article about the Initial server setup with Centos 7.

How to Install Node from the Epel-repository on Centos 7

An easy way to install Node.js on Centos 7 is from the Epel-repository.

Node.js is available in the Centos repository by default. You need to install Epel-repository first with the following command:

sudo yum install epel-release

When you have finished you will see in your output similar to this:

Output
Installed:
epel-release.noarch 0:7-11
Complete!

Here you can install Node.js on Centos 7 with the following command:

sudo yum install nodejs

Your output will be:

Output
Installed:
nodejs.x86_64 1:6.17.1-1.el7
Dependency Installed:
libicu.x86_64 0:50.2-4.el7_7 libuv.x86_64 1:1.41.0-1.el7 npm.x86_64 1:3.10.10-1.6.17.1.1.el7
Complete!

If you want to check that you have successfully installed the Node.js run the following command:

node --version
Output
v6.17.1

If you see the Node.js version in your output it means that your installation was successful.

You may want to access “npm” to manage their packages. you can also get this from the Epel-repository:

sudo yum install npm

How to Install Node from source on Centos 7

One way to install Node.js on Centos 7 is to get the source code and assemble it yourself.

At this point, you need to get the source code from the download page of the Node.js website. copy the link address of the source code then run the following command with that address you have copied.

wget https://nodejs.org/dist/v14.17.5/node-v14.17.5.tar.gz

After this, you need to extract the archive and move it into the new directory with the following command:

sudo tar xzvf node-v* && cd node-v*

Here to assemble the code you need to download a few packages from the Centos repository. Run the following command:

sudo yum install gcc gcc-c++

Your output will similar to this:

Output
Installed:
  gcc.x86_64 0:4.8.5-44.el7            gcc-c++.x86_64 0:4.8.5-44.el7
Dependency Installed:
  cpp.x86_64 0:4.8.5-44.el7
  glibc-devel.x86_64 0:2.17-324.el7_9
  glibc-headers.x86_64 0:2.17-324.el7_9
  kernel-headers.x86_64 0:3.10.0-1160.36.2.el7
  libmpc.x86_64 0:1.0.1-3.el7
  libstdc++-devel.x86_64 0:4.8.5-44.el7
  mpfr.x86_64 0:3.1.1-4.el7
Dependency Updated:
  glibc.x86_64 0:2.17-324.el7_9        glibc-common.x86_64 0:2.17-324.el7_9
  libgcc.x86_64 0:4.8.5-44.el7         libgomp.x86_64 0:4.8.5-44.el7
  libstdc++.x86_64 0:4.8.5-44.el7
Complete!

At this point, you can configure and assemble the software:

./configure
make

When it is finished, you can install the software with the following command:

sudo make install

If you want to be sure that your installation was successful you can ask for the node version if you see the version of Node.js means that was successfully installed on Centos 7.

node --version
Output
v14.17.5

How to Install a package from the Node site on Centos 7

Another way to install Node.js on Centos 7 is to get the pre-built packages from the Node.js website and install them.

You can find the Linux binaries(x64) packages from the Node.js website. copy the link address then paste it in the following command then run it:

cd ~
wget https://nodejs.org/dist/v14.17.5/node-v14.17.5-linux-x64.tar.xz

After this, you need to extract the binary package into your local package hierarchy with the following command:

sudo tar --strip-components 1 -xzvf node-v* -C /usr/local

You can verify the installation with the following command:

node --version
Output
 v14.17.5

If you see the Node.js version means that your installation was successful.

How to Install Node Using Node version manager on Centos 7

Another way of installing Node.js that is through NVM, the Node version manager. This piece of software allows you to install and hold many different independent versions of Node.js, and their associated Node packages, at the same time.

To install NVM on your CentOS 7, visit the project’s GitHub page. Copy the curl or wget command from the README file that displays on the main page.

Remove the “| bash” part at the end of the command the run it:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh

Take a look and make sure you are comfortable with the changes it is making.

Then run the command with “| bash” at the end:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

This will install the nvm script to your user account. To use it, you must first source your .bash_profile:

source ~/.bash_profile

Now you can ask NVM which versions of Node it knows about:

nvm list-remote

Here you can install any version you want.

To install v14.17.5 run the following command:

nvm install v14.17.5

you can see which versions you have installed with the following command:

nvm list
output
->  v14.17.5
      system

You can switch between them by typing:

nvm use v14.17.5
Now using node v14.17.5

To set this version as the default, type:

nvm alias default v14.17.5
Output
default -> v14.17.5

You can verify that the installation was successful using the same way as the other parts, by the following command:

node --version
Output
v14.17.5

Conclusion

At this point, you learn different ways of installing Node.js on Centos 7. If one of the installation ways is giving you errors, try one of the other ways.

Hope you enjoy it on the Orcacore website.

Also, another article that will be useful for you:

How to install NGINX on centos 7

How to install Apache on centos 7

Related Articles
2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular