How To Install an Upstream Version of Node.js on Ubuntu

Node.js is a software platform that is used to build fast and easily scalable applications. Node.js utilizes JavaScript as its scripting language, and achieves high throughput via non-blocking I/O and a single-threaded event loop.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Nginx, and allowing more control of how the web server works.

In order to install node.js on our Ubuntu server, we need to install some prerequisites first. Before installing any package we should make sure that our repositories are up to date:

# sudo apt-get update

Once we are done with the update, we need to install the build-essentials package. This package contains an informational list of packages which are considered essential for building Debian packages.

# sudo apt-get install build-essential

We also need to install curl package. It is a library that lets us make HTTP requests in the command line.

# sudo apt-get install curl

One curl is installed, we have all packages required prior to installing NodeJS. There are more different ways to install NodeJS. The easiest one is to simply execute:

# sudo apt-get install nodejs

However, the latest Node.js version might not be in the standard repository. In order to make sure that we have the latest version we are going to download the source, compile and install it, rather than using apt-get. First, we will change our current path to include ~/local/bin directory and then source the .bashrc file:

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc

Then, we will create the directories required for the installation process:

mkdir ~/{local,node-latest-install}

Then, we switch to the latest-install folder and use curl to download the Node.js archive and then unpack it using tar.