How to install Node.js on Ubuntu Linux 16.04 LTS server

Posted on in Categories , , , last updated May 10, 2017

How do I install Node.js (“Javascript for server-side programming”) on an Ubuntu Linux 16.04 LTS server using command line only option?

Node.js is an open source program to write server application in JavaScript. It is a built on Chrome’s JavaScript runtime. Back in the old days, JavaScript was used primarily for client-side scripting. Node.js allows JavaScript to be used for server-side scripting and output dynamic web page for users. This tutorial shows you how to install Node.js on an Ubuntu Linux 16.04 LTS server.

Method #1: Install the bundled distro specif Node.js version 4.2.6

Type the following apt command or apt-get command to install both npm and nodejs:
$ sudo apt install nodejs
OR
$ sudo apt-get install nodejs npm
Sample outputs:

Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libuv1
The following NEW packages will be installed:
  libuv1 nodejs
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 3218 kB of archives.
After this operation, 13.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu xenial/universe amd64 libuv1 amd64 1.8.0-1 [57.4 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 nodejs amd64 4.2.6~dfsg-1ubuntu4.1 [3161 kB]
Fetched 3218 kB in 6s (519 kB/s)                                                                                                                                            
Selecting previously unselected package libuv1:amd64.
(Reading database ... 32088 files and directories currently installed.)
Preparing to unpack .../libuv1_1.8.0-1_amd64.deb ...
Unpacking libuv1:amd64 (1.8.0-1) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_4.2.6~dfsg-1ubuntu4.1_amd64.deb ...
Unpacking nodejs (4.2.6~dfsg-1ubuntu4.1) ...
Processing triggers for libc-bin (2.23-0ubuntu7) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libuv1:amd64 (1.8.0-1) ...
Setting up nodejs (4.2.6~dfsg-1ubuntu4.1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
Processing triggers for libc-bin (2.23-0ubuntu7) ...

Verify version:
$ nodejs --version
v4.2.6
$ npm --version
3.5.2

Method #2: Install the latest version of Node.js version 6.x or 7.x

The syntax is as follows to install Node.js version 6.x (stable LTS and recommended for production usage):
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs build-essential

Sample outputs:

Fig.01: Installing LTS version of Node.js on an Ubuntu 16.04 server
Fig.01: Installing LTS version of Node.js on an Ubuntu 16.04 server

The syntax is as follows to install Node.js version 7.x (current/latest and recommended for testing purpose):
$ curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
$ sudo apt-get install -y nodejs build-essential

Verify it

Type the following commands:
$ nodejs --version
v6.10.3
$ npm --version
3.10.10

And there you have it, Node.js installed and working. You can start writing apps now. See the official website for more information.

Leave a Comment