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.

cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1

Next, we will set the parameters so Node.JS is installed for the current user and run the installation:

./configure --prefix=~/local
make install

Once Node.JS is installed, we will also install the node package manager (npm), which is the official package manager for Node.JS

curl https://npmjs.org/install.sh | sh

In order to check which Node.JS version we have currently installed on our server, we should execute:

# node -v

That is all. Now we node.js installed and we are ready to create and deploy our first application.

Try this tutorial on an SSD cloud server for $5.00/month only!

Built for Developers: 512MB RAM, 20GB SSD Disk and 2TB Transfer. 30 second setup.
  • bcs

    Pl can you show how to install node.js/express.js/mariadb/mongodb on CentOS?

    • mnaser

      Sure, we’ll add that to our tutorial list to be written.