Procedure to install Node.js 11.x on Ubuntu 16.x/18.x, CentOS 7.x through binary distribution or from the source.
Node.js popularity is growing faster than ever. If you recently started learning Nodejs development, then one of the first things you need to do is to install them.
Technically, there are multiple ways to get things installed but following the easy and right process will make life much easier.
The following, I’ve tested on DigitalOcean server. Let’s get it started.
Ubuntu 16.x or 18.x
The latest version of Nodejs is not available through the default repository. But not to worry, you can use NodeSource distribution as the following.
- Log in to the server as root
- Execute the following
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
The above will download and install the NodeSource Node.js repository. At the end of the above output, you should see something like this.
Reading package lists... Done ## Run `sudo apt-get install -y nodejs` to install Node.js 11.x and npm ## You may also need development tools to build native addons: sudo apt-get install gcc g++ make ## To install the Yarn package manager, run: curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update && sudo apt-get install yarn
- Next, you will have to install the nodejs with the following command.
apt-get install -y nodejs
It will take a few seconds and once done; you should be able to verify the version.
[email protected]:~# nodejs -v v11.7.0 [email protected]:~#
And, as you can see, it has installed 11.7.0 version.
First, you need to install the NodeSource repository with the following command.
curl -sL https://rpm.nodesource.com/setup_11.x | bash -
And then, install the Nodejs as below.
yum install -y nodejs
It will take a few seconds, and at the end, you should see something like below.
Running transaction Installing : 2:nodejs-11.7.0-1nodesource.x86_64 1/1 Verifying : 2:nodejs-11.7.0-1nodesource.x86_64 1/1 Installed: nodejs.x86_64 2:11.7.0-1nodesource Complete! [[email protected] ~]#
This means the Node.js is installed and can be verified with
[[email protected] ~]# node -v v11.7.0 [[email protected] ~]#
The above instruction should also work for Fedora 29 or later.
Installing from Source Code
What if you are in a DMZ environment where you can’t connect to the Internet? You still can install by building the source code. The procedure is not as easy as above through binary distribution but doable.
- Login to Ubuntu or CentOS server
- Download the latest or the one you want from here using
wget. I am trying the latest one.
- Extract the downloaded file with
tar -xvf node-v11.7.0.tar.gz
- You should see a new folder created in the present working directory
drwxr-xr-x 9 502 501 4096 Jan 17 21:27 node-v11.7.0
- Go to the newly created folder
And, its time to build the Node.js from source now.
But, before you proceed, ensure you have the pre-requisites installed.
If using Ubuntu then install the pre-requisites with below
apt-get update apt-get install gcc g++ clang make
and for CentOS
yum update yum install gcc clang gcc-c++
- Let’s built it now
- Ensure no error and then next
make make install
It will take some time to build and once done; you can verify the installed version by executing below.
[email protected]:~# node --version v11.7.0 [email protected]:~#
You see, installing Nodejs is easy. Nex, you may want to learn and understand Nodejs.