How Install NodeJS in Ubuntu 16.04 LTS Xenial

June 17, 2016 | By in UBUNTU HOWTO
| Reply More

NodeJS is a free and open source javascript runtime developed on Chrome's V8 JavaScript engine which is designed to build scalable network applications. It allows the use of Javascript in the server side programming which has the ability to interact with the operating system and networking. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. Here in this article, we'll learn how to install the latest and stable NodeJS in our machine running Ubuntu 16.04 LTS Xenial. To install NodeJS, we have many methods we can use. The following are the ways we'll feature in this article.

  • Installing using the Official Repository
  • Installing using the Github Source Code Clone
  • Installing using Node Version Manager (NVM)

Installing using the Official Repository

First of all, as NodeJS is available in the official repository of Ubuntu 16.04 LTS Xenial, we can easily install it using the repository. In order to do so, we'll first need to update the local repository index of our apt package manager.

$ sudo apt-get update

Once the update is completed, we'll move ahead and run the following command to upgrade our system which will upgrade the packages to the latest available versions.

$ sudo apt-get upgrade

Then, we'll install nodejs using the apt-get command. Doing so will automatically install the node package manager which comes by default with nodejs. NPM allows us to install node packages from the Node Package Manager Repository.

$ sudo apt-get install nodejs nodejs-legacy

Installing Nodejs Nodejs-legacy

Once done, we'll be able to install and run our node applications successfully.

Installing using the Github Source Code Clone

If we wanna install the nodejs from the latest clone of Github Source Code then we'll need to follow this method of installation.

First of all, we'll need to make sure that the dependencies required for the compilation of NodeJS is installed in our Ubuntu 16.04 machine. So, in order to install it, we'll need to update the local repository index of the apt package manager.

$ sudo apt-get update

Once done, we'll now install the required dependencies from the repository.

$ sudo apt-get install make gcc g++ python

install dependencies git clone

We'll now need to download the official release of nodejs from its Offical Github Repo . To do so, we'll run the following wget command to the respective release of nodejs.

$ wget

Once the tarballs are downloaded, we'll want to extract it using the following command.

$ tar zxvf v6.2.1.tar.gz

Then, we'll move ahead towards the compilation of it by running the following commands.

$ cd node-6.2.1
$  ./configure

Configuring Nodejs

Once its compiled successfully, we'll gonna install it in our machine running 16.04 LTS.

$ sudo make install

Make Install Nodejs

The installation process may take much more time depending upon the performance of the machine.

Installing using Node Version Manager (NVM)

The Node Version Manager also known as NVM is a version managing script for nodejs that allows us to manage multiple versions of Node.js to use in the same machine. In order to install NVM, we'll require that curl, libssl-dev and build-essential are installed. In order to do so, we'll need to run the following command.

$ sudo apt-get update
$ sudo apt-get install build-essential libssl-dev curl

Installing NVM Dependencies

Once the dependencies are installed, we'll now install the latest release of NVM from its Github repository using curl.

$ curl -o- | bash

Installing NVM

Now, in order to gain access to the NVM functionalities and binaries, we'll need to make sure to source ~/.profile file as the installer has appended the required settings in it.

$ source ~/.profile

In order to apply the changes, we'll need to make sure to logout and login to the session.

Once done, we'll move ahead towards the installation of the latest nodejs in our machine using NVM. Here, we can see all the available versions of nodejs that we want to install. To do so, we'll need to execute the following command.

$ nvm ls-remote

Node Versions NVM

Then, we'll need to run the following command to install it.

$ nvm install v6.2.1

Installing Node with NVM

Once its installed, we can switch the version of nodejs by simply running the following command.

$ nvm use v6.2.1

Testing NodeJS Installation

As we have completed the installation of NodeJS using the above steps, we should be now able to even check the version of nodejs by running the following command.

$ node -v


Now, we'll gonna create a simple nodejs app printing our all time favorite "Hello World" statement. We'll create a file named hello.js using a text editor.

$ nano hello.js

Then, we'll write the following javascript code to the hello.js file.

console.log('Hello World! '+a+' '+b);

Hello World Nodejs

Once done, we'll gonna save and execute the javascript file using nodejs.

$ node hello.js

Hello World Output Nodejs


Finally we have successfully installed the latest and stable available NodeJS in our machine running Ubuntu 16.04 LTS Xenial. This tutorial should work fine in almost all the derivatives of Ubuntu and Debian. NodeJs has completely changed the way we used to run Javascripts. Nodejs has made Javascript available to run out of the web browsers ranging from servers to home desktop applications. After the above installation of NodeJs is completed, we can now run our various nodejs applications. If you have any questions, comments, feedback please do write on the comment box below and let us know what stuffs needs to be added or improved.


Share This :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.