Terug naar het artikeloverzicht

How to install Node.js on Ubuntu 20.04

Code on a computer screen
Photo by Ferenc Almasi on Unsplash

In this guide, we'll show you how to install Node.js on Ubuntu 20.04. Before you get started, you'll need a non-root user account with sudo privileges.

There's more than one way to install Node.js, so we'll walk you through a few of them.

Installing Node.js

There are three common ways to install Node.js on your system: with apt from Ubuntu's default repository, with apt from the NodeSource repository, or with nvm (Node Version Manager). We'll cover all three, starting with the simplest.

Option 1: Install from Ubuntu's software repository

You can use Ubuntu's default software repository to install Node.js with apt. This is the quickest option, but the version it installs is not the most current.

First, start fresh with an update:

sudo apt update && sudo apt upgrade -y

Now install Node.js from the Ubuntu repository. Add npm if you also want the Node.js package manager:

sudo apt install nodejs npm

After the installation finishes, check the version:

nodejs -v

On Ubuntu 20.04, the output will be:

v10.19.0

Node.js 10 reached end of life in 2021 and no longer receives security updates, so for anything beyond quick testing, use one of the options below to install a current version.

Option 2: Install from the NodeSource repository

This option installs Node.js from a repository maintained by NodeSource. It's useful because it lets you choose which version of Node.js to install.

First, use curl to download the setup script for the version you need:

cd ~
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh

setup_lts.x installs the current long-term support (LTS) release. To install a specific major version, replace lts with its number, for example setup_22.x.

Run the script to add the NodeSource repository to your system:

sudo -E bash nodesource_setup.sh

Then install Node.js (npm is included with the NodeSource package):

sudo apt install nodejs

After the installation finishes, check the version:

node -v

This should output the version you chose.

Option 3: Install with nvm

nvm (Node Version Manager) installs Node.js in your user account and makes it easy to switch between versions, which is handy if different projects need different versions. Download and run the install script (check the nvm GitHub page for the latest release number):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.bashrc

Then install the latest LTS version of Node.js and check it:

nvm install --lts
node -v

Whichever method you choose, you've now successfully installed Node.js on your Ubuntu 20.04 web server.


If you have questions about any of our services, please contact us via email at [email protected] or by using our live chat at spinservers.com.

Spin Servers is a US-based provider of dedicated servers & affordable private cloud solutions. Our motto is to let you "spin up servers" fast, seamlessly, and affordably.