tutorials questions & answers
by Mark

Installing NodeJS on an Ubuntu 16.04 VPS Server

  • nodejs
  • ubuntu
  • server
  • nvm
  • github


What is NodeJS?
NodeJS is a free 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 official repository
Installing using the Github Source Code Clone
Installing using Node Version Manager (NVM)


  1. An ubuntu vps server from vpsserver.com, you can order one at https://www.vpsserver.com/plans/.
  2. An ssh client such as Bitvise or Putty.
  3. Knowledge in linux command line is an advantage.

To learn how to install NodeJS on a CentOS server please follow this guide.

Installing using the Official Repository

Installing NodeJS using the official Ubuntu repository is fairly easy. In order to do so we will have to update our local repository of our package manager first. We can do the with the below command:

sudo apt-get update

Once the update procedure is complete, we can move on to upgrading our installed packages to their latest versions. Follow the command below:

sudo apt-get upgrade

Afterwards, we can now install NodeJS using the apt-get install command. Doing this will automatically install the NodeJS package manager which will come with a default NodeJS installation. Please enter the command:

sudo apt-get install nodejs nodejs-legacy

john@locahost:~$ sudo apt-get install nodejs nodejs-legacy
Reading package list... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
The following new packages will be installed:
	libuv1   nodejs   nodejs-legacy
Do you want to continue? [Y/n] y

Once NodeJS is installed we can now run our node applications.

Installing using the Github Source code

Lets say you want to go on an advanced installation procedure and would like to have the latest NodeJS version available on Github. You can do so by downloading the latest NodeJS Github source and install it on your server.

But first, before we can do just that we will have to installed the required pre-requisite packages for NodeJS and here is how to do it.

We will need to update and uprade our Ubuntu server to the latest packages. We can do that by:

sudo apt-get update
sudo apt-get upgrade

Once upgraded we can now install the required dependencies for NodeJS.
sudo apt-get install make gcc g++ python
Afterwards we will need to download the official release of NodeJS from its official Github Repository. We can do that by using the wget command:
wget https://github.com/nodejs/node/archive/v6.2.1.tar.gz

Once downloading is done we would want to extract it using the command:
tar zxvf v6.2.1.tar.gz

Then we can go ahead by entering the source folder and configuring it.
cd node-6.2.1

Once compilation is successful we can now install it on our Ubuntu server.
sudo make install

The installation process may take a longer time all depending on the performance of the server being used.

Installing using the Node Version Manager (NVM)

The Node Version Manager or also known as NVM is a version control script for nodejs that allows us to manage multiple NodeJS versions on the same machine. In order to install NVM we will need some required packages such as curl, libssl-dev and build-essentials to be installed. In order to do that we we will need to run the commands below:
sudo apt-get update
sudo apt-get install build-essential libssl-dev curl

Once all the required dependencies are installed we can now start the installation for the latest version of NVM. To do so, we will have to download NVM from the Github Repo using curl.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash

Once done, in order to have access to NVM functionalities and binaries we will need to source ~/.profile. We can do that will the following command below:
source ~/.profile

Logout and login back into the session in order to apply the changes.

Once you are back in the session we can now go ahead with the installation of the latest NodeJS package available on NVM. Execute the below command to see all the available versions:
nvm ls-remote


We will need to run the following command to install the latest version which is v6.2.1 as of this writing:
nvm install v6.2.1

Once installed we can switch to this version by using the below command:
nvm use v6.2.1
To verify the version currently being used you can execute the following command:
node -v Result should be:

Testing our NodeJS installation

Once our installation is done we can now go ahead and test our installation of NodeJS. To do that we have to create a file named myhello.js using our favorite text editor.

nano myhello.js

Open the file and write the following piece of code:

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

Once its done, close and save the file.
To run the file enter the following command:
node myhello.js

john@localhost:~$ node myhello.js
Hello World! by VPSServer.com

Now that our NodeJS installation is done wle can now go ahead with create our application. If you have any suggestions and comments regarding this article please do not hesitate to write a comment below.

comments (0)

    leave comment

    Please choose login or register to comment in this thread.

    Start now for as low as $5 a month!

    • 8 Characters
    • 1 Uppercase Atleast
    • 1 Number Atleast