How to Install Node.js and npm on Ubuntu 22.04

Many web applications, build tools, and command-line utilities need Node.js and npm before you can install or run them. Node.js is a JavaScript runtime built on Chrome’s V8 engine, with npm as its default package manager and the world’s largest software registry. On Ubuntu 22.04, the Node.js version you end up with depends on where you install it from.
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
v26.x,v24.x, andv22.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.22.9) is outdated and should not be used in production.
Choose the method that fits your needs. If you are not sure which version to install, check the documentation of the application you are deploying.
Quick Reference
| Task | Command |
|---|---|
| Install via NodeSource | sudo apt install nodejs (after adding repo) |
| Install via nvm | nvm install --lts |
| Install via Ubuntu repo | sudo apt install nodejs npm |
| 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> |
| Upgrade to a new major (nvm) | nvm install <version> --reinstall-packages-from=<old> |
| 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:
- v26.x - The latest LTS version (Lithium).
- v24.x - Maintenance LTS version (Krypton).
- v22.x - Maintenance LTS version (Jod), supported until April 2027.
Node.js 20 reached end-of-life in April 2026. Its node_20.x repository is still online, but it no longer receives security fixes.
We will install Node.js version 26.x. If you need another version, change NODE_MAJOR=26 to your preferred version (for example, NODE_MAJOR=24). Run the following command to create the NodeSource repository file:
NODE_MAJOR=26
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 the node, npm, and npx binaries.
To verify that Node.js and npm were successfully installed, run the following command to print their versions:
node --versionv26.13.1npm --version11.20.0After 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 will 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.41.0/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.41.0To 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.
...
v22.23.4 (LTS: Jod)
v22.23.5 (Latest LTS: Jod)
...
v24.22.2 (LTS: Krypton)
v24.22.3 (Latest LTS: Krypton)
...
v26.13.0 (LTS: Lithium)
v26.13.1 (Latest LTS: Lithium) (Latest: node)Each LTS release is labeled with the codename of its release line. The (Latest: node) label marks the newest Node.js release overall.
To install the latest LTS version of Node.js, run:
nvm install --ltsThe output should look something like this:
Installing latest LTS version.
Downloading and installing node v26.13.1...
...
Now using node v26.13.1 (npm v11.20.0)
Creating default alias: default -> lts/* (-> v26.13.1)Once the installation is completed, verify it by printing the Node.js version:
node -vv26.13.1Install two more versions, the latest Node.js 24 release and version 22.23.5:
nvm install 24
nvm install 22.23.5You can list the installed Node.js versions by typing:
nvm lsThe output should look something like this:
-> v22.23.5
v24.22.3
v26.13.1
default -> lts/* (-> v26.13.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v26.13.1) (default)
stable -> 26.13 (-> v26.13.1) (default)
lts/* -> lts/lithium (-> v26.13.1)
...
lts/iron -> v20.20.2 (-> N/A)
lts/jod -> v22.23.5
lts/krypton -> v24.22.3
lts/lithium -> v26.13.1The entry with an arrow (-> v22.23.5) is the Node.js version used in the current shell session. The default alias points to lts/*, which currently resolves to v26.13.1. The default version is the version that will be active when opening new shells.
To change the currently active version:
nvm use 24Now using node v24.22.3 (npm v11.19.1)To change the default Node.js version:
nvm alias default 24For 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 upstream in April 2022. Ubuntu published its last security update for the package in June 2024. 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:
node -vv12.22.9npm -v8.5.1Both versions are several major releases behind the current Node.js and npm releases. Many current npm packages require a newer Node.js version and will not run on Node.js 12.
Upgrading Node.js
The upgrade steps depend on how you installed Node.js.
For a NodeSource install, write the new release line to the repository file and install the package again. The following commands move Node.js 24 to Node.js 26:
NODE_MAJOR=26
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
sudo apt update
sudo apt install nodejsAPT upgrades the nodejs package in place. You do not need to remove the old version first. If your project uses packages with native addons, run npm rebuild in the project directory to compile them against the new Node.js version.
The Ubuntu repository stays on Node.js 12 for the whole life of Ubuntu 22.04. Running sudo apt upgrade will never move you to a newer release line. To get one, switch to NodeSource or nvm.
With nvm, install the new version and copy the global packages from the old one:
nvm install 26 --reinstall-packages-from=24The old version stays installed. Once your projects work on Node.js 26, make it the default with nvm alias default 26.
Troubleshooting
npm: command not found
The Ubuntu nodejs package does not include npm. Install it separately with sudo apt install npm. NodeSource and nvm install npm together with Node.js.
node: command not found after installing nvm
The installer adds nvm to your shell startup file. A terminal that was already open during the install has not read the new lines yet. Open a new terminal, or load nvm in the current one:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"trying to overwrite '/usr/include/node/common.gypi'
The Ubuntu libnode-dev package is still installed. It ships the same file as the NodeSource nodejs package, so dpkg stops the installation. Remove the Ubuntu Node.js packages, then install from NodeSource again:
sudo apt remove nodejs npm libnode-dev
sudo apt autoremove
sudo apt install nodejsAPT still installs Node.js 12 after adding NodeSource
APT has not loaded the NodeSource repository yet. Run sudo apt update, then check the candidate version with apt policy nodejs. If the candidate is still 12.22.9, check /etc/apt/sources.list.d/nodesource.list for typos.
Uninstalling Node.js
The uninstall method depends on how you installed Node.js.
NodeSource or Ubuntu repository:
sudo apt remove nodejs npm
sudo apt autoremoveIf you used NodeSource, also delete the repository file and the signing key:
sudo rm /etc/apt/sources.list.d/nodesource.list /etc/apt/keyrings/nodesource.gpg
sudo apt updatenvm:
nvm uninstall 22.23.5To completely remove nvm, delete the ~/.nvm directory and remove the nvm lines from your ~/.bashrc or ~/.zshrc file.
Conclusion
NodeSource installs a supported Node.js release that you update with APT, like any other system package. nvm is the better choice when different projects need different Node.js versions on the same machine.
To keep a Node.js application running in the background, see our guide on managing Node.js processes with PM2 .
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 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page