Contact Us

How to install NodeJS on Linux (CentOS/Ubuntu) – LinuxTechLab

Mobile App | April 7, 2021

Node.js or as commonly called NodeJS, is an open source , cross platform Java Run time environment based Chrome’s V8 JavaScript engine, meant for server-side programming. It allows us to run scripts on server-side to produce dynamic web page content before the page is sent to the user’s web browser. It allows to easily develop networked applications that require back-end functionality with Java-scripts being used on both front-end & back-end.

Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. In this tutorial, we will learn to install Node.JS on Ubuntu & CentOS machines.

(Recommended Read: – )

Pre-requisites

We need to have some packages like ‘gcc, gcc-c++’ installed on our systems. Install them on CentOS using the following command,

$ sudo yum install gcc gcc-c++

For Ubuntu, install them using the following command,

$ sudo apt-get install build-essential

Install NodeJS on Ubuntu

We can install either of the two available Node.JS versions i.e. 6 (which has long term support) or 9 (which is the latest version available). For installing Node.JS, we will add the official repositories on our system, use the following command to add the repository,

For Node.JS 6,

$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash –

For Node.JS 9,

$ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash –

Once added, install Node.JS using the following command,

$ sudo apt-get install nodejs

We can also install Node.JS using the source code, method has been discussed below.

Install NodeJS on CentOS

On CentOS, we can either install Node.JS from EPEL repository or from official Node.JS repositories. Both methods have been shared below.

Using EPEL repository

To use this method for Node.JS installation, we need to add the EPEL repositories on our system first. Execute one of the following mentioned command, based on the OS & architecture being used,

RHEL/CentOS 7

$ sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

RHEL/CentOS 6 (64 Bit)

$ sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

RHEL/CentOS 6 (32 Bit)

$ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

Once done install, Node.JS using yum,

$ sudo yum install nodejs

Using Official repository

To use the official repository to install Node.JS, execute the following command based on the version needed,

Node.JS 6

$ curl –silent –location https://rpm.nodesource.com/setup_6.x | sudo bash –

Node.JS 9

$ curl –silent –location https://rpm.nodesource.com/setup_9.x | sudo bash –

Then install Node.JS using yum,

$ sudo yum install nodejs

Install NodeJS from source

We can also install Node.JS on both Ubuntu & CentOS by building it from source. Use the following process to install latest version of Node.Js i.e. version 9 on Ubuntu as well CentOS,

Download the latest source code,

$ wget https://nodejs.org/dist/v9.1.0/node-v9.1.0.tar.gz

$ tar -xvzf node-v9.1.0.tar.gz

$ cd node-v9.1.0

Next compile the source code with the following commands,

& install it using the following command,

$ sudo make install

This will install the latest version of Node.JS on your system. To check the version number of Node.JS, run the following command,

$ node – -version

With this we end our tutorial on how to install NodeJS on Linux machines. In our upcoming tutorial, we will discuss .

If have any doubts or questions, please feel free to send them to us using the comment box below.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: | |

Donate us some of you hard earned money:

Linux TechLab is thankful for your continued support.

This content was originally published here.