Install node.js on Ubuntu

This page explains how to install node.js on Ubunutu. The following has been performed with the following versions:

Update your system

Start by updating your system with the following commands:

sudo apt update -y
sudo apt upgrade -y

Install node.js

The simplest way to install node.js is to use apt-get:

sudo apt install nodejs

Install npm

I strongly recommand to install npm (Node.js Packet Manager) with node.js. The following command installs npm:

sudo apt install npm

Versions

You can check that node.js is successfully installed by checking the version curently installed:

node -v

In my case, this is the version 8.10.0. If you want the lastest version, run the following commands to clean npm's cache and install n for managing versions:

sudo npm cache clean -f
sudo npm install -g n

You can now upgrade node.js to the latest version:

sudo n stable
PATH="$PATH"

Now, check which version is currently installed with node -v. In my case, the latest stable version is the 12.16.0.

If you need a specific version, you can install like this:

sudo n 13.8.0
PATH="$PATH"

See also


Last update : 02/17/2020