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?
Different Ways To Install Node.js on Centos 7
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 to your server as a non-root user with Sudo privileges. To do this, you can check our article about the Initial server setup with Centos 7.
Method 1 – Install Nodejs From the Yum 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-220.127.116.11.1.el7 Complete!
If you want to check that you have successfully installed the Node.js run the following command:
If you see the Node.js version in your output it means that your installation was successful.
Installing npm package manager on Centos 7
You may want to access “npm” to manage their packages. You can also get this from the Epel repository:
sudo yum install npm
Method 2 – Install Nodejs 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:
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 be 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:
# sudo ./configure # sudo 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:
Method 3 – Install a package from the Nodejs 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 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:
If you see the Node.js version means that your installation was successful.
Method 4 – Install Nodejs Using Node version manager (NVM) on Centos 7
Another way of installing Node.js 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:
Now you can ask NVM which versions of Node it knows about:
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:
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:
At this point, you have learned 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. It is recommended to always use the LTS version.
Hope you enjoy it on the Orcacore website.
Also, another article that will be useful for you: