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

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
$ sudo apt-get install nodejs npm
Sample outputs:

Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
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 xenial/universe amd64 libuv1 amd64 1.8.0-1 [57.4 kB]
Get:2 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
$ npm --version

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 | 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

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

Verify it

Type the following commands:
$ nodejs --version
$ npm --version

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

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...