Install Latest Nodejs and NPM Version in Linux Systems

In this guide, we shall 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...

In this guide, we shall 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 Linux, Fedora, Debian 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 https://rpm.nodesource.com/setup_6.x | 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 'https://rpm.nodesource.com/pub_6.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.69QmXPKxPE' 'https://rpm.nodesource.com/pub_6.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## 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 https://rpm.nodesource.com/setup_7.x | bash -

On Debian, Ubuntu and Linux Mint

$ sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
Sample Output
## Installing the NodeSource Node.js v6.x repo...
## Populating apt-get cache...
+ apt-get update
Get:1 http://security.ubuntu.com/ubuntu yakkety-security InRelease [102 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu yakkety-security/main i386 Packages [109 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu yakkety-updates InRelease [102 kB]
Get:5 http://security.ubuntu.com/ubuntu yakkety-security/main amd64 Packages [112 kB]
Get:6 http://security.ubuntu.com/ubuntu yakkety-security/universe amd64 Packages [56.5 kB]
Get:7 http://security.ubuntu.com/ubuntu yakkety-security/universe i386 Packages [54.3 kB]
Get:8 http://us.archive.ubuntu.com/ubuntu yakkety-backports InRelease [102 kB]
Get:9 http://security.ubuntu.com/ubuntu yakkety-security/universe Translation-en [35.2 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 Packages [224 kB]
Get:11 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main i386 Packages [221 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main Translation-en [100.0 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe amd64 Packages [144 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe i386 Packages [142 kB]
Get:15 http://us.archive.ubuntu.com/ubuntu yakkety-updates/universe Translation-en [76.2 kB] Get:16 http://us.archive.ubuntu.com/ubuntu yakkety-updates/multiverse amd64 Packages [4,632 B] Get:17 http://us.archive.ubuntu.com/ubuntu 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 'https://deb.nodesource.com/node_6.x/dists/yakkety/Release'
## Adding the NodeSource signing key to your keyring...
+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
OK
## Creating apt sources list file for the NodeSource Node.js v6.x repo...
+ echo 'deb https://deb.nodesource.com/node_6.x yakkety main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src https://deb.nodesource.com/node_6.x yakkety main' >> /etc/apt/sources.list.d/nodesource.list
## Running `apt-get update` for you...
+ apt-get update
Get:1 http://security.ubuntu.com/ubuntu yakkety-security InRelease [102 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety InRelease [247 kB] Get:3 http://us.archive.ubuntu.com/ubuntu yakkety-updates InRelease [102 kB]
Get:4 https://deb.nodesource.com/node_6.x yakkety InRelease [3,915 B]
Get:5 http://us.archive.ubuntu.com/ubuntu yakkety-backports InRelease [102 kB]
Get:6 https://deb.nodesource.com/node_6.x yakkety/main Sources [765 B]
Get:7 https://deb.nodesource.com/node_6.x yakkety/main i386 Packages [961 B]
Get:8 https://deb.nodesource.com/node_6.x 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 https://deb.nodesource.com/setup_7.x | 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: centos.mirror.snu.edu.in
* elrepo: mirror.cedia.org.ec
* epel: ftp.jaist.ac.jp
* extras: centos.mirror.snu.edu.in
* remi-safe: mirror.cedia.org.ec
* rpmforge: mirrors.digipower.vn
* updates: centos.mirror.snu.edu.in
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-1.6.9.4.2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================
Installing:
nodejs x86_64 1:6.9.4-2.el7 epel 4.6 M
npm x86_64 1:3.10.10-1.6.9.4.2.el7 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-1.6.9.4.2.el7.x86_64.rpm | 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.6.9.4.2.el7.x86_64 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-1.6.9.4.2.el7.x86_64 2/2 Installed:
nodejs.x86_64 1:6.9.4-2.el7 npm.x86_64 1:3.10.10-1.6.9.4.2.el7 Complete!

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:
nodejs
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 https://deb.nodesource.com/node_6.x 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
CentOS 7- Check Nodejs and NPM Version

CentOS 7 – Check Nodejs and NPM Version

On Debian, Ubuntu and Linux Mint

$ nodejs --version
$ npm --version
Ubuntu 15.10 - Check Nodejs and NPM Version

Ubuntu 15.10 – Check Nodejs and NPM Version

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

I believe these were easy and simple steps to follow but in case of problems you faced, you can let us know and we find ways of helping you. Hope this guide was helpful to you and always remember to stay connected to Tecmint.

Posted by wiredgorilla