How to Install Node.js and npm on Ubuntu 26.04

Ubuntu 26.04 ships Node.js in its own repositories, but the version you get there is not always the version your project needs. Node.js runs JavaScript outside the browser, and npm installs the packages your application depends on. The install method you pick up front decides how much work it takes to change versions later.
This guide covers three ways to install Node.js and npm on Ubuntu 26.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. Ubuntu 26.04 includes Node.js
v22.22.1, which is suitable for many applications.
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 maintains an APT repository with multiple Node.js versions. Use this method when you need a specific version.
Install the required dependencies:
sudo apt update
sudo apt install ca-certificates curl gnupgImport the NodeSource GPG key:
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.gpgNodeSource provides the following versions:
- v26.x - The current release.
- v24.x - The latest LTS version (Krypton).
- v22.x - Maintenance LTS version (Jod).
NodeSource also still publishes a node_20.x repository, but Node.js 20 reached end-of-life in 2026 and no longer receives security fixes.
NodeSource provides Debian packages for amd64 and arm64. If dpkg --print-architecture reports another architecture, use the Ubuntu repository or nvm instead.
We will install Node.js version 24.x. Change NODE_MAJOR=24 to your preferred version if needed:
NODE_MAJOR=24
ARCH=$(dpkg --print-architecture)
sudo tee /etc/apt/sources.list.d/nodesource.sources > /dev/null <<EOF
Types: deb
URIs: https://deb.nodesource.com/node_${NODE_MAJOR}.x
Suites: nodistro
Components: main
Architectures: ${ARCH}
Signed-By: /etc/apt/keyrings/nodesource.gpg
EOFInstall Node.js and npm:
sudo apt update
sudo apt install nodejsThe nodejs package includes both node and npm binaries.
Verify the installation:
node --versionYou should see output similar to this:
v24.19.0npm --versionThe output will show the npm version bundled with the installed Node.js release:
11.17.0After npm is installed, see the npm command guide for package installs, updates, scripts, and lock-file based installs.
To compile native addons from npm, install the development tools:
sudo apt install build-essentialInstalling Node.js and npm using NVM
NVM (Node Version Manager) is a bash script that lets you manage multiple Node.js versions per user. This is the preferred method for developers who need to switch between versions.
Download and install nvm:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bashDo not use sudo
, as it will enable nvm for the root user only.
The script clones the repository to ~/.nvm and adds the required lines to your shell profile:
=> 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_completionEither close and reopen your terminal or run the commands above to load nvm in the current session.
Verify the installation:
nvm -v0.40.6List all available Node.js versions:
nvm list-remote...
v22.23.2 (Latest LTS: Jod)
...
v24.19.0 (Latest LTS: Krypton)
...
v26.7.0Install the latest Node.js version:
nvm install node...
Now using node v26.7.0 (npm v11.19.0)
Creating default alias: default -> node (-> v26.7.0)This installs the current release rather than an LTS release. For a server you plan to leave running, install an LTS version instead, as shown below.
Verify the installation:
node -vv26.7.0Install additional versions:
nvm install --lts
nvm install 22List installed versions:
nvm ls-> v22.23.2
v24.19.0
v26.7.0
default -> node (-> v26.7.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v26.7.0) (default)
stable -> 26 (-> v26.7.0) (default)
lts/* -> lts/krypton (-> v24.19.0)
lts/jod -> v22.23.2
lts/krypton -> v24.19.0The arrow (-> v22.23.2) indicates the active version. In this example, installing Node.js 22 selected it, but nvm use can select any installed version. The default version activates when opening new shells.
Switch to a different version:
nvm use 24Now using node v24.19.0 (npm v11.17.0)Change the default version:
nvm alias default 24Installing Node.js and npm from the Ubuntu repository
Ubuntu 26.04 includes Node.js v22.22.1 in its default repositories. This version works well for many applications and receives security updates through Ubuntu.
Install Node.js and npm:
sudo apt update
sudo apt install nodejs npmUbuntu packages nodejs and npm separately, so both names are needed here.
Verify the installation:
node -vv22.22.1npm -v9.2.0Ubuntu ships an older npm than the one bundled with Node.js 22 upstream, which is worth knowing if a project expects a newer npm. To compile native addons from npm packages, install the build tools as well:
sudo apt install build-essentialUpgrading Node.js
Moving to a newer release line works differently for each installation method.
If you installed Node.js from NodeSource, point the repository file at the new release line and reinstall the package. This example moves an existing Node.js 22 install up to Node.js 24:
SOURCE_FILE=/etc/apt/sources.list.d/nodesource.sources
[ -f "$SOURCE_FILE" ] || SOURCE_FILE=/etc/apt/sources.list.d/nodesource.list
sudo sed -i 's#node_22\.x#node_24.x#' "$SOURCE_FILE"
sudo apt update
sudo apt install nodejsAPT replaces the installed nodejs package in place, so you do not need to remove the old version first. Packages with compiled native addons may still need to be reinstalled against the new Node.js version.
The Ubuntu repository only offers the release line that shipped with 26.04, so sudo apt upgrade keeps you on Node.js 22. To reach a newer version, switch to NodeSource or nvm using one of the methods above.
With nvm, install the new version and bring your global packages along in the same command:
nvm install 24 --reinstall-packages-from=22The --reinstall-packages-from option reinstalls every global npm package from the version you name, which saves setting them up by hand. The older version stays on disk, so you can switch back to it while you test.
Troubleshooting
npm: command not found after installing from Ubuntu
Ubuntu splits Node.js and npm into separate packages. Install npm with sudo apt install npm, or use NodeSource or nvm, which both bundle npm with Node.js.
node: command not found after installing nvm
nvm loads from your shell profile, so it is not available until that profile runs. Close and reopen your terminal, or load it in the current shell:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"nvm works in one terminal but not another
Check that the nvm lines were added to the shell file you actually use, such as ~/.bashrc, ~/.zshrc, or ~/.profile.
APT still installs the old version after adding NodeSource
Run sudo apt update after writing the repository file, then confirm the candidate version with apt policy nodejs. If Ubuntu’s package still wins, the repository file was not written correctly.
Permission errors installing global npm packages
Avoid working around these with sudo, since it leaves root-owned files in your home directory. On a development machine, nvm avoids the problem because global packages are installed under your own user account.
Uninstalling Node.js
The uninstall method depends on how you installed Node.js.
NodeSource or Ubuntu repository:
sudo apt remove nodejs npm
sudo apt autoremovenvm:
nvm uninstall 24To completely remove nvm, delete the ~/.nvm directory and remove the nvm lines from your ~/.bashrc or ~/.zshrc file.
Conclusion
If you are deploying rather than experimenting, install an LTS release and pin it. A release in the Current phase may later enter LTS, while a release line that does not enter LTS has a much shorter support window. Check the Node.js releases page for end-of-life dates before you commit to a version.
To put Node.js into production with PM2 and Nginx, see How to Deploy a Node.js Application on Ubuntu 26.04 .
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