How To Install Node.js on Ubuntu 22.04

In this guide, we want to teach you How To Install Node.js on Ubuntu 22.04.

Node.js is open-source and completely free, used by thousands of developers around the world. It brings plenty of advantages to the table, making it a better choice than other server-side platforms like Java or PHP.

Steps To Install Node.js on Ubuntu 22.04

In this tutorial, we will show you to install Node.js on Ubuntu 22.04, in three different ways.

  1. Install Nolde.js using the APT repository
  2. Using the PPA repository
  3. Using the nvm (Node Version Manager)

Before you start to complete this guide, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Ubuntu 22.04.

Now follow the steps below to install Node.js on your server.

Install Nodejs With APT repository on Ubuntu 22.04

First, update your local package index with the following command:

sudo apt update

Then, install Node.js on Ubuntu 22.04 with the command below:

sudo apt install nodejs

Now you can verify your Node.js installation by checking its version:

node -v

Also, you can install the npm (Node.js Package Manager) with the following command:

sudo apt install npm

Install Nodejs with the PPA repository on Ubuntu 22.04

To install a different version of Node.js, you can use a PPA (personal package archive) maintained by NodeSource. These PPAs have more versions of Node.js available than the official Ubuntu repositories. Node.js v14, v16, and v18 are available as of the time of writing.

To download the installation script for your preferred version, you can use the curl command:

# cd ~
# curl -sL -o

When your download is completed, run your installation script:

sudo bash

The PPA will be added to your configuration and your local package cache will be updated automatically. You can now install the Node.js package in the same way you did in the previous section.

sudo apt install nodejs

Verify your Node.js installation on Ubuntu 22.04 with the command below:

node -v

Note: The NodeSource nodejs package contains both the node binary and npm, so you don’t need to install npm separately.

Install Nodejs using the NVM (Node Version Manager) on Ubuntu 22

Another way of installing Node.js that is particularly flexible is to use nvm, the Node Version Manager. This piece of software allows you to install and maintain many different independent versions of Node.js, and their associated Node packages, at the same time.

First, you need to visit the GitHub Project page and copy the curl command from the README file that displays on the main page.

Then, run the command without the | bash segment at the end of the command:

curl -o-

Take a look and make sure you are comfortable with the changes it is making. When you are satisfied, run the command again with | bash appended at the end.

curl -o- | bash

Next, source your .bashrc file:

source ~/.bashrc

To check which versions of Node are available, run the following command:

nvm list-remote
. . .
       v16.13.0   (LTS: Gallium)
       v16.13.1   (LTS: Gallium)
       v16.13.2   (LTS: Gallium)
       v16.14.0   (Latest LTS: Gallium)

To get the Node.js v16.14.0 (Latest LTS: Gallium) you can run the command below on Ubuntu 22.04:

nvm install v16.14.0

Now you can see the different versions you have installed with the following command:

nvm list
->     v16.14.0
default -> v16.14.0
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.14.0) (default)
stable -> 16.14 (-> v16.14.0) (default)
lts/* -> lts/gallium (-> v16.14.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.10 (-> N/A)
lts/fermium -> v14.19.0 (-> N/A)
lts/gallium -> v16.14.0

Note: if you also have a version of Node.js installed through apt, you may see an system entry here. You can always activate the system-installed version of Node using nvm use system.


At this point, you learn to Install Node.js on Ubuntu 22.04.

Hope you enjoy it.

You may also be interested in this article about How To Install Node.js on Centos 7.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!