How To Install Node.js on CentOS 7

How To Install Node.js on CentOS 7


Node.js is a Javascript platform created for the purpose of server-side programming. The platform allows users to create applications that require backend functionality. This program is further used to offer full-stack services and for front-end purposes.

Node.js has a default package manager called the Node Package Manager (npm) that helps in the publication of open-source packages for Node.js.

This guide will take you through different approaches when installing Node.js and npm on a CentOS 7 server. First, we will look at how to use the yum packages from NodeSource in the installation of Node.js and then show you how to use nvm script when installing Node.js and npm.

Let’s get started.

Step 1 – Installing Node.js and Node.js Package Manager from The NodeSource

NodeSource company provides efficient Node services and ensures there is an up-to-date Node.js repository for Linux.

The following steps will help you with the installation of Node.js and npm using the NodeSource repository on CentOS server.

1. Adding NodeSource yum Repository

The first step is to include the NodeSource repository to your server. If the current Node.js LTS version is 8.x, and you require version 10, simply change the setup_8.x with setup_10.x. Then use the command below to add this yum repository:

$ curl -sL | sudo bash -

2. Installing Node.js And Node.js Package Manager With yum

After enabling the repository, now start installing Node.js and npm using the command below:

$ sudo yum install nodejs

3. Verifying The installation Of Node.js and npm

To confirm that Node.js installation went through, run the commands below to print the current versions of Node.js and npm.

To confirm the actual version of Node.js run the command below:

$ node --version

The output should look like this:


To check the Node.js Package Manager version:

$ npm --version

The output should look like this:


Step 2 – Installing Node.js using NVM

Node Version Manager (NVM) is a described as a script that helps a user to manage different versions of Node.js. You can use it in the process of installing and uninstalling a certain version of Node.js which allows the user to have several versions of Node.js you need to test or use.

Follow these steps to start installing Node.js and npm with NVM on CentOS server.

1. Installing Node Version Manager (NVM)

Start by downloading the nvm script using the command below:

$ curl -o- | bash

This script will act as a replica to the nvm repository derived from Github to ~/.nvm. Add this script to Bash or the ZSH profile.

The output should look like this:

 => Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s"$NVM_DIR/" ] && . "$NVM_DIR/"  # This loads nvm
[ -s"$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

From the results above, it is clear that you need to either close your terminal and reopen it or just run the following commands to include the pathway to the nvm script as well as your recent session.

To confirm that nvm is installed, run the command below:

$ nvm --version

The output should be like this:


2. Installing Node.js With NVM

After installing nvm on your system, now install the current Node.js version using the command below:

$ nvm install node

The output should look like this:

Downloading and installing node v10.1.0...
Computing checksum with sha256sum
Checksums matched!
Now using node v10.1.0 (npm v5.6.0)
Creating default alias: default -> node (-> v10.1.0)

Now, confirm the actual version of Node.js you’re using, run the following command:

$ node --version

The output should be:


3. Installing different versions of Node.js with NVM

Next, install two additional versions of Node.js i.e the latest version of LTS and version 6.14.2

$ nvm install --lts
$ nvm install 6.14.2

Once they are installed, type:

$ nvm ls

The output should look like this:

->      v6.14.2                 # ACTIVE VERSION
default -> node (-> v10.1.0)    # DEFAULT VERSION
node -> stable (-> v10.1.0) (default)
stable -> 10.1 (-> v10.1.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.11.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.2
lts/carbon -> v8.11.1

From the output, the entry (-> v6.14.2) indicates the actual version in this shell session while the entry v10.1.0 indicates the default version. When the new shells open, the default version will become active.

4. Changing The Node.js version using NVM

To modify the currently active version of Node.js, run the command below:

$ nvm use 8.11.1

Verify the version with the following:

$ nvm current

The output:


5. Changing the default version of Node.js using NVM

To change the default Node.js version to 8.11.1 run the command below:

$ nvm alias default 8.11.1

Step 3: Installing The Development Tools

To can create modules with nvm, you will be required to start by installing the development tools:

$ sudo yum install gcc-c++ make

Step 4: Installing The Yarn Package Manager

Yarn is a popular package manager by JavaScript that works fine with npm. The program helps to speed up the building process of packages and reduce errors associated with network connectivity.

To get the most updated version, you have to check it out on the Yarn’s official repository and it’s the most recommended method to install Yarn version that works for the CentOS system.

Follow these steps to begin Yarn installation using yum on the CentOS server:

1. Adding Yarn yum repository

Begin by adding the GPK key to your machine together with the repository using these commands:

$ curl --silent --location | sudo tee /etc/yum.repos.d/yarn.repo
$ sudo rpm --import

2. Installing Yarn on CentOS 7

After adding the repository, now start installing the Yarn package with the command below:

$ sudo yum install yarn

3. Verifying the Installation

To make sure the installation is successful, print the version number using the command below:

$ yarn --version

The output should look like this:


That’s it.


That’s it! You have installed Node.js and npm on your CentOS system using two different methods. The choice of your method will depend on your preferences. While the NodeSource repository helps to install the packaged version of Node.js, nvm method can be used to either add or remove multiple Node.js versions when needed.

Check out these top 3 Node.js hosting services:

$1.79 /mo
Starting price
Visit FastComet
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing

How to install and configure Node.js on Debian 9

This tutorial will help you install and configure Node.j and Node.js Package Man
5 min read
David Malcom
David Malcom

How To Install Node.js On Ubuntu 18.04

This tutorial will help you install the latest version of Node.js; a cross-platf
4 min read
David Malcom
David Malcom

How To Set up a VSFTPD Server on a CentOS 7 VPS or Dedicated Server

Brief Description FTP is usually insecure exposing clear-text passwords, userna
2 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How to Install MongoDB on Your CentOS 7 VPS or Dedicated Server

MongoDB is designed for extensive databases and is mainly used for data analytic
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top