How to Install Node.js and npm on Ubuntu 26.04
Node.js is an open-source JavaScript runtime built on Chrome’s V8 engine. It lets you run JavaScript outside the browser and is commonly used for APIs, command-line tools, and server-side applications. npm is the default package manager for Node.js.
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
v25.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.x, 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> |
| 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:
- v25.x - The current release.
- v24.x - The latest LTS version (Krypton).
- v22.x - Maintenance LTS version (Jod).
We will install Node.js version 24.x. Change NODE_MAJOR=24 to your preferred version if needed:
NODE_MAJOR=24
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.listInstall 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.x
npm --versionThe output will show the npm version bundled with the installed Node.js release:
11.x
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.3/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_completion
Either close and reopen your terminal or run the commands above to load nvm in the current session.
Verify the installation:
nvm -v0.40.3
List all available Node.js versions:
nvm list-remote...
v22.x (LTS: Jod)
...
v24.x (LTS: Krypton)
...
v25.x
Install the latest Node.js version:
nvm install node...
Now using node v25.x (npm v11.x)
Creating default alias: default -> node (-> v25.x)
Verify the installation:
node -vv25.x
Install additional versions:
nvm install --lts
nvm install 22List installed versions:
nvm ls-> v22.x
v24.x
v25.x
default -> node (-> v25.x)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v25.x) (default)
stable -> 25 (-> v25.x) (default)
lts/* -> lts/krypton (-> v24.x)
lts/jod -> v22.x
lts/krypton -> v24.x
The arrow (-> v22.x) indicates the active version. The default version activates when opening new shells.
Switch to a different version:
nvm use 24Now using node v24.x (npm v11.x)
Change the default version:
nvm alias default 24Installing Node.js and npm from the Ubuntu repository
Ubuntu 26.04 includes Node.js v22.x 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 npmThis installs Node.js along with the tools needed to compile native addons from npm.
Verify the installation:
node -vv22.x
npm -v10.x
Uninstalling 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 24To 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 26.04. NodeSource provides specific versions, nvm offers flexibility for managing multiple versions, and the Ubuntu repository includes a stable LTS version out of the box.
For more information, see the official Node.js documentation .












