How to 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, andv20.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
| Task | Command |
|---|---|
| Install via NodeSource | sudo apt install nodejs (after adding repo) |
| Install via nvm | nvm install --lts |
| Check Node.js version | node -v |
| Check npm version | npm -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.js | sudo 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:
sudo apt update
sudo apt install ca-certificates curl gnupgNext, import the Nodesource repository’s GPG key to your system:
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.gpgAt 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:
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.listOnce the repository is enabled, install Node.js and npm:
sudo apt update
sudo apt install nodejsThe 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:
node --versionv22.15.0npm --version10.9.2After 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:
sudo apt install build-essentialInstalling 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:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bashDo 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:
=> 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_completionAs 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:
nvm -v0.40.3To get a list of all Node.js versions that can be installed with nvm, run:
nvm list-remoteThe command will print a vast list of all available Node.js versions.
...
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.0To install the latest available version of Node.js, run:
nvm install nodeThe output should look something like this:
...
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:
node -vv25.0.0Let’s install two more versions, the latest LTS version and version 22.15.0:
nvm install --lts
nvm install 22.15.0You can list the installed Node.js versions by typing:
nvm lsThe output should look something like this:
-> 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.0The 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:
nvm use 24.12.0Now using node v24.12.0 (npm v10.9.2)To change the default Node.js version:
nvm alias default 24.12.0For more detailed information about using the nvm script, visit the project’s GitHub page.
Installing Node.js and npm from the Ubuntu repository
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:
sudo apt update
sudo apt install nodejs npmThis installs Node.js along with the tools needed to compile native addons from npm.
Verify the installation:
nodejs -vv12.22.9Uninstalling Node.js
The uninstall method depends on how you installed Node.js.
NodeSource or Ubuntu repository:
sudo apt remove nodejs
sudo apt autoremovenvm:
nvm uninstall 22.15.0To 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 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