How To Install Latest Nodejs and NPM Version in Linux Systems

In this guide, we'll take a look at how you can install the latest version of Nodejs and NPM in RHEL/CentOS and Fedora distributions.

Nodejs is a lightweight and efficient JavaScript platform which is built based on Chrome’s V8 JavaScript engine and NPM is a default NodeJS package manager. You can use it to build scalable network applications.

Step 1: Adding NodeSource Repository

The latest version of Node.js and NPM is available from the official NodeSource Enterprise LinuxFedoraDebian and Ubuntu binary distributions repository, which is maintained by the Nodejs website and you will need to add it to your system to be able to install the latest Nodejs and NPM packages.

Important: Under RHEL 5 and CentOS 5, the Node.js packages are depend on the EPEL repository, so the script will check and give instructions if incase it’s not installed.

To add the repository for the latest version of Node.js v6 LTS, use the following command as root..

On RHEL, CentOS and Fedora

# curl --silent --location | bash -
Sample Output
## Installing the NodeSource Node.js 6.x repo...
## Inspecting system...
+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m
## Confirming "el7-x86_64" is supported...
+ curl -sLf -o /dev/null ''
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.69QmXPKxPE' ''
## Installing release setup RPM...
+ rpm -i --nosignature --force '/tmp/tmp.69QmXPKxPE'
## Cleaning up...
+ rm -f '/tmp/tmp.69QmXPKxPE'
## Checking for existing installations...
+ rpm -qa 'node|npm' | grep -v nodesource
## Run `yum install -y nodejs` (as root) to install Node.js 6.x and npm.
## You may also need development tools to build native addons:
##   `yum install -y gcc-c++ make`

Alternatively for Node.js v7 add the following repository.

------- For Node.js v7 -------
# curl --silent --location | bash -

On Debian, Ubuntu and Linux Mint

$ sudo curl -sL | sudo -E bash -
Sample Output
## Installing the NodeSource Node.js v6.x repo...
## Populating apt-get cache...
+ apt-get update
Get:1 yakkety-security InRelease [102 kB]
Get:2 yakkety InRelease [247 kB]
Get:3 yakkety-security/main i386 Packages [109 kB]
Get:4 yakkety-updates InRelease [102 kB]
Get:5 yakkety-security/main amd64 Packages [112 kB]
Get:6 yakkety-security/universe amd64 Packages [56.5 kB]
Get:7 yakkety-security/universe i386 Packages [54.3 kB]
Get:8 yakkety-backports InRelease [102 kB]
Get:9 yakkety-security/universe Translation-en [35.2 kB]
Get:10 yakkety-updates/main amd64 Packages [224 kB]
Get:11 yakkety-updates/main i386 Packages [221 kB]
Get:12 yakkety-updates/main Translation-en [100.0 kB]
Get:13 yakkety-updates/universe amd64 Packages [144 kB]
Get:14 yakkety-updates/universe i386 Packages [142 kB]
Get:15 yakkety-updates/universe Translation-en [76.2 kB]                                                                                                 
Get:16 yakkety-updates/multiverse amd64 Packages [4,632 B]                                                                                               
Get:17 yakkety-updates/multiverse Translation-en [2,252 B]                                                                                               
Fetched 1,835 kB in 7s (261 kB/s)                                                                                                                                                            
Reading package lists... Done
## Confirming "yakkety" is supported...
+ curl -sLf -o /dev/null ''
## Adding the NodeSource signing key to your keyring...
+ curl -s | apt-key add -
## Creating apt sources list file for the NodeSource Node.js v6.x repo...
+ echo 'deb yakkety main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src yakkety main' >> /etc/apt/sources.list.d/nodesource.list
## Running `apt-get update` for you...
+ apt-get update
Get:1 yakkety-security InRelease [102 kB]
Get:2 yakkety InRelease [247 kB]     
Get:3 yakkety-updates InRelease [102 kB]
Get:4 yakkety InRelease [3,915 B]
Get:5 yakkety-backports InRelease [102 kB]
Get:6 yakkety/main Sources [765 B]
Get:7 yakkety/main i386 Packages [961 B]
Get:8 yakkety/main amd64 Packages [964 B]
Fetched 560 kB in 2s (215 kB/s)   
Reading package lists... Done
## Run `apt-get install nodejs` (as root) to install Node.js v6.x and npm

Alternatively for Node.js v7 add the following repository.

$ sudo curl -sL | sudo -E bash -

Step 2: Install Latest Nodejs and NPM

Next, you can now install Nodejs and NPM on your system using the command below:

On RHEL, CentOS and Fedora

# yum -y install nodejs npm
# dnf -y install nodejs npm   [On Fedora 22+ versions]
Sample Output
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager, versionlock
This system is not registered with Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
* base:
* elrepo:
* epel:
* extras:
* remi-safe:
* rpmforge:
* updates:
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 1:6.9.4-2.el7 will be installed
---> Package npm.x86_64 1:3.10.10- will be installed
--> Finished Dependency Resolution
Dependencies Resolved
Package                    Arch                       Version                                        Repository                Size
nodejs                     x86_64                     1:6.9.4-2.el7                                  epel                     4.6 M
npm                        x86_64                     1:3.10.10-                        epel                     2.4 M
Transaction Summary
Install  2 Packages
Total download size: 7.0 M
Installed size: 26 M
Downloading packages:
(1/2): npm-3.10.10-                                                                   | 2.4 MB  00:00:25     
(2/2): nodejs-6.9.4-2.el7.x86_64.rpm                                                                          | 4.6 MB  00:01:02     
Total                                                                                                116 kB/s | 7.0 MB  00:01:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:npm-3.10.10-                                                                                1/2 
Installing : 1:nodejs-6.9.4-2.el7.x86_64                                                                                       2/2 
Verifying  : 1:nodejs-6.9.4-2.el7.x86_64                                                                                       1/2 
Verifying  : 1:npm-3.10.10-                                                                                2/2 
nodejs.x86_64 1:6.9.4-2.el7                                   npm.x86_64 1:3.10.10-                                  

On Debian, Ubuntu and Linux Mint

$ sudo apt-get install -y nodejs
Sample Output
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 106 not upgraded.
Need to get 10.3 MB of archives.
After this operation, 52.1 MB of additional disk space will be used.
Get:1 yakkety/main amd64 nodejs amd64 6.10.1-1nodesource1~yakkety1 [10.3 MB]
Fetched 10.3 MB in 45s (224 kB/s)                                                                                                   
Selecting previously unselected package nodejs.
(Reading database ... 65830 files and directories currently installed.)
Preparing to unpack .../nodejs_6.10.1-1nodesource1~yakkety1_amd64.deb ...
Unpacking nodejs (6.10.1-1nodesource1~yakkety1) ...
Setting up nodejs (6.10.1-1nodesource1~yakkety1) ...
Processing triggers for man-db (2.7.5-1) ...

Optional: There are development tools such as gcc-c++ and make that you need to have on your system, in order to build native addons from npm.

------- On RHEL, CentOS and Fedora -------
# yum install gcc-c++ make
------- On Debian, Ubuntu and Linux Mint -------
$ sudo apt-get install -y build-essential

Step 3: Testing Latest Nodejs and NPM

To have a simple test of nodejs and NPM, you can just check the versions installed on your system by using the following commands:

On RHEL, CentOS and Fedora

# node --version
# npm --version

On Debian, Ubuntu and Linux Mint

$ nodejs --version
$ npm --version

That is it, Nodejs and NPM are now installed and ready for use on your system.

  • nodejs, nmp
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to change maximum upload size in php.ini

  There are a few common errors that occur in Wordpress and other PHP-based programs that use...

How to change the primary IP address of a cPanel server

Steps in WHM: Log into WHM and go to Basic cPanel & WHM Setup Change the Primary IP here...

How to install WordPress with Docker on Ubuntu 16.04

Before we start, it is necessary to install Docker and Docker Compose. On Ubuntu 16.04, this can...

How to enable the gzip/deflate in nginx server on a Linux or Unix system

Ever thought of enabling gzip compression on nginx web server for JS/CSS/HTML files? Here is...

How to Upgrade Kernel to Latest Version in Ubuntu

It is important to keep your systems up-to-date, here we'll show you how to upgrade your kenerl...