How to Install Node.js and npm on Ubuntu 22.04

By 

Updated on

6 min read

Install Node.js and npm on Ubuntu 22.04

Node.js is a cross-platform, open-source JavaScript runtime environment built on Chrome’s V8 JavaScript engine. It allows you to execute JavaScript code outside a web browser and is commonly used to build fast and scalable server-side applications. npm is the default package manager for Node.js and the world’s largest software registry.

This guide covers three ways to install Node.js and npm on Ubuntu 22.04:

  • NodeSource repository - Install a specific Node.js version. NodeSource supports Node.js v24.x, v22.x, and v20.x.
  • nvm (Node Version Manager) - Manage multiple Node.js versions on the same machine. This is the preferred method for developers.
  • Ubuntu repository - The easiest way, but the included version (v12.x) is outdated and should not be used in production.

Choose the method that fits your needs. If unsure which version to install, check the documentation of the application you’re deploying.

Quick Reference

TaskCommand
Install via NodeSourcesudo apt install nodejs (after adding repo)
Install via nvmnvm install --lts
Check Node.js versionnode -v
Check npm versionnpm -v
List installed versions (nvm)nvm ls
Switch Node.js version (nvm)nvm use <version>
Set default version (nvm)nvm alias default <version>
Uninstall Node.jssudo apt remove nodejs or nvm uninstall <version>

Installing Node.js and npm from NodeSource

NodeSource is a company focused on providing enterprise-grade Node support. It maintains an APT repository containing multiple Node.js versions. Use this repository if your application requires a specific version of Node.js.

The first step is to install the dependencies necessary to add a new repository . Most likely, you will already have those packages installed on your system, but some packages may be missing:

Terminal
sudo apt update
sudo apt install ca-certificates curl gnupg

Next, import the Nodesource repository’s GPG key to your system:

Terminal
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

At the time of writing, the NodeSource repository provides the following versions:

  • v24.x - The latest LTS version (Krypton).
  • v22.x - Active LTS version (Jod).
  • v20.x - Maintenance LTS (EOL April 2026).

We’ll install Node.js version 22.x. If you need another version, change NODE_MAJOR=22 to your preferred version (e.g., NODE_MAJOR=24). Run the following command to create the NodeSource repository file:

Terminal
NODE_MAJOR=22
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Once the repository is enabled, install Node.js and npm:

Terminal
sudo apt update
sudo apt install nodejs

The nodejs package contains both the node and npm binaries.

To verify that the Node.js and npm were successfully installed, run the following command to print their versions:

Terminal
node --version
output
v22.15.0
Terminal
npm --version
output
10.9.2

After npm is installed, see the npm command guide for package installs, updates, scripts, and lock-file based installs.

To be able to compile native addons from npm, you’ll need to install the development tools:

Terminal
sudo apt install build-essential

Installing Node.js and npm using NVM

NVM (Node Version Manager) is a bash script that allows you to manage multiple Node.js versions on a per-user basis. With NVM, you can install and uninstall any Node.js version that you want to use or test.

Visit the nvm GitHub repository page and copy either the curl or wget command to download and install the nvm script:

Terminal
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

Do not use sudo , as it will enable nvm for the root user.

The script will clone the project’s repository from GitHub to the ~/.nvm directory:

output
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

As the output above says, you should either close and reopen the terminal or run the commands to add the path to the nvm script to the current shell session. You can do whatever is easier for you.

Once the script is in your PATH, verify that nvm was properly installed by typing:

Terminal
nvm -v
output
0.40.3

To get a list of all Node.js versions that can be installed with nvm, run:

Terminal
nvm list-remote

The command will print a vast list of all available Node.js versions.

output
...
       v20.19.0   (LTS: Iron)
       v20.19.1   (Latest LTS: Iron)
...
       v22.14.0   (LTS: Jod)
       v22.15.0   (Latest LTS: Jod)
...
       v24.12.0   (LTS: Krypton)
        v25.0.0

To install the latest available version of Node.js, run:

Terminal
nvm install node

The output should look something like this:

output
...
Now using node v25.0.0 (npm v11.0.0)
Creating default alias: default -> node (-> v25.0.0)

Once the installation is completed, verify it by printing the Node.js version:

Terminal
node -v
output
v25.0.0

Let’s install two more versions, the latest LTS version and version 22.15.0:

Terminal
nvm install --lts
nvm install 22.15.0

You can list the installed Node.js versions by typing:

Terminal
nvm ls

The output should look something like this:

output
->    v22.15.0
      v24.12.0
       v25.0.0
default -> node (-> v25.0.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v25.0.0) (default)
stable -> 25.0 (-> v25.0.0) (default)
lts/* -> lts/krypton (-> v24.12.0)
lts/iron -> v20.19.1 (-> N/A)
lts/jod -> v22.15.0
lts/krypton -> v24.12.0

The entry with an arrow (-> v22.15.0) is the Node.js version used in the current shell session, and the default version is set to v25.0.0. The default version is the version that will be active when opening new shells.

To change the currently active version:

Terminal
nvm use 24.12.0
output
Now using node v24.12.0 (npm v10.9.2)

To change the default Node.js version:

Terminal
nvm alias default 24.12.0

For more detailed information about using the nvm script, visit the project’s GitHub page.

Installing Node.js and npm from the Ubuntu repository

Note
The Node.js version in Ubuntu 22.04 repositories (v12.22.9) reached end-of-life in April 2022. It no longer receives security updates. Use NodeSource or nvm instead for production environments.

The installation is straightforward:

Terminal
sudo apt update
sudo apt install nodejs npm

This installs Node.js along with the tools needed to compile native addons from npm.

Verify the installation:

Terminal
nodejs -v
output
v12.22.9

Uninstalling Node.js

The uninstall method depends on how you installed Node.js.

NodeSource or Ubuntu repository:

Terminal
sudo apt remove nodejs
sudo apt autoremove

nvm:

Terminal
nvm uninstall 22.15.0

To completely remove nvm, delete the ~/.nvm directory and remove the nvm lines from your ~/.bashrc or ~/.zshrc file.

Conclusion

We covered three ways to install Node.js and npm on Ubuntu 22.04. NodeSource provides specific versions, nvm offers flexibility for managing multiple versions, and the Ubuntu repository (though outdated) provides the simplest installation.

For more information, see the official Node.js documentation .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page