Mixing Node.js package sources on Ubuntu is one of the fastest ways to break your toolchain. Ubuntu ships an older version by default, NodeSource tracks upstream LTS releases through APT, and NVM lets you switch versions per project without touching system packages. This guide covers all three ways to install Node.js on Ubuntu so you pick the right one and verify it actually works before writing any code.
Install Node.js on Ubuntu
Compare the three methods before choosing one:
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| Ubuntu Repository | Ubuntu Repos | Distribution default | Automatic with apt upgrade | Stable baseline installs |
| NodeSource Repository | NodeSource | Current LTS or Current release | Automatic with apt upgrade | Developers tracking active Node.js lines |
| Node Version Manager (NVM) | NVM GitHub | Any supported Node.js release | Manual with nvm install | Per-project version switching |
If you only need one Node.js version and want automatic security updates through apt upgrade, start with Method 1 or Method 2. Pick NVM if your projects require different Node.js versions.
These instructions cover Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS.
Methods 2 and 3 use the same commands across all supported releases. Method 1 uses the same install command, but the default Node.js version depends on your Ubuntu release.
Before installing, update the package index and apply any pending security updates:
sudo apt update && sudo apt upgrade
New to sudo? See the guide on adding a user to sudoers on Ubuntu before continuing.
Method 1: Install Node.js from Ubuntu Repository
The Ubuntu repository gives you a Node.js version tied to your Ubuntu release with no extra repository setup or GPG key management.
Default Node.js Versions in Ubuntu Repositories
| Ubuntu Release | Default nodejs | Default npm | Upstream Status |
|---|---|---|---|
| Ubuntu 26.04 LTS | 22.x | 9.2.x | Maintenance LTS |
| Ubuntu 24.04 LTS | 18.x | 9.2.x | End-of-life |
| Ubuntu 22.04 LTS | 12.x | 8.5.x | End-of-life |
Install nodejs and npm together since Ubuntu ships them as separate packages:
sudo apt install -y nodejs npm
Verify both installed correctly:
node --version
npm --version
# Ubuntu 26.04 LTS v22.22.0 9.2.0 # Ubuntu 24.04 LTS v18.19.1+dfsg 9.2.0 # Ubuntu 22.04 LTS v12.22.9 8.5.1
Ubuntu appends the +dfsg suffix to some package versions to indicate Debian/Ubuntu source repackaging; it does not mean this is a different Node.js upstream release.
Ubuntu 22.04 ships Node.js 12, which reached end-of-life in April 2022. Ubuntu 24.04 ships Node.js 18, which is also end-of-life. For current projects on either release, use Method 2 (NodeSource) or Method 3 (NVM). See the official Node.js end-of-life schedule for details.
Method 2: Install Node.js from NodeSource Repository on Ubuntu
NodeSource publishes dedicated Node.js APT packages for every major release line, so you can pin to Node.js 22, 24, or a future release and receive upstream security patches without waiting for Ubuntu’s packaging cycle.
Install Node.js Prerequisites
Install curl, CA certificates, and gpg, which are required to download and verify the NodeSource repository:
sudo apt install -y curl ca-certificates gpg
Import NodeSource GPG Key
Download and store the NodeSource GPG key to verify package authenticity. First, create the keyrings directory if it does not exist:
sudo install -m 0755 -d /etc/apt/keyrings
Next, download the GPG key and convert it to the binary format APT requires:
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor --batch --yes -o /etc/apt/keyrings/nodesource.gpg
Set NodeSource Node.js Version on Ubuntu
Create the repository configuration file. Set NODE_MAJOR to your target major version, then paste the block. NodeSource uses nodistro as a universal suite name that works across all supported Ubuntu releases:
NODE_MAJOR=24
cat <<EOF | sudo tee /etc/apt/sources.list.d/nodesource.sources
Types: deb
URIs: https://deb.nodesource.com/node_$NODE_MAJOR.x
Suites: nodistro
Components: main
Signed-By: /etc/apt/keyrings/nodesource.gpg
EOF
Choose from the currently supported Node.js versions:
NODE_MAJOR=20: Maintenance LTS (Iron), nearing end-of-life and best avoided for new projectsNODE_MAJOR=22: Maintenance LTS (Jod)NODE_MAJOR=24: Active LTS (Krypton), recommended for most new projectsNODE_MAJOR=25: Current release with latest features and a shorter support window
To use Node.js 22 on Ubuntu 24.04 instead, set NODE_MAJOR=22 in the command block above before running apt update and apt install.
Node.js 24 (Krypton) is the current Active LTS release and recommended for most new projects. Choose Node.js 22 or 20 if your existing project requires them. Check the Node.js releases page for current support schedules.
Install Node.js from NodeSource
Update the package index to pick up the new repository:
sudo apt update
# Example output on Ubuntu 24.04 Hit:1 https://deb.nodesource.com/node_24.x nodistro InRelease Hit:2 http://archive.ubuntu.com/ubuntu noble InRelease Hit:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease Reading package lists... Done
Confirm nodejs is being offered by NodeSource before installation:
apt-cache policy nodejs | sed -n '1,8p'
nodejs:
Installed: (none)
Candidate: 24.14.0-1nodesource1
Version table:
24.14.0-1nodesource1 500
500 https://deb.nodesource.com/node_24.x nodistro/main amd64 Packages
Install Node.js. NodeSource bundles npm inside the nodejs package, so no separate npm package is required:
sudo apt install -y nodejs
node --version
npm --version
v24.14.0 11.9.0
Method 3: Install Node.js with Node Version Manager (NVM) on Ubuntu
NVM installs Node.js into your home directory and keeps each version isolated. No repository setup, no sudo, and the same commands work on Ubuntu 22.04, 24.04, and 26.04.
Install NVM on Ubuntu 26.04, 24.04, and 22.04
NVM is a shell function, not a system binary. Download and run the install script using curl:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
Or use wget if curl is not installed:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
The script appends NVM initialization lines to your shell config. Load them into your current session without restarting the terminal:
source ~/.bashrc
Confirm NVM loaded correctly:
command -v nvm
nvm
NVM is a shell function, not a binary.
which nvmalways returns nothing, so usecommand -v nvmto verify it is available. See the which command guide for more on how shell lookups work. Zsh users should source~/.zshrcinstead of~/.bashrc.
List Available Node.js Versions with NVM
View all available Node.js versions:
nvm ls-remote
LTS releases are marked with their codenames (Iron, Jod, Krypton). To show only LTS versions:
nvm ls-remote --lts
Install a Node.js Version with NVM on Ubuntu
Install the latest LTS version:
nvm install --lts
Alternatively, install a specific version by number:
nvm install 24
Downloading and installing node v24.14.0... Downloading https://nodejs.org/dist/v24.14.0/node-v24.14.0-linux-x64.tar.xz... ######################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v24.14.0 (npm v11.9.0)
node --version
npm --version
v24.14.0 11.9.0
Switch Between Node.js Versions with NVM
Once you have multiple versions installed, switching is one command. First, add another version:
nvm install 22
Switch to a different installed version:
nvm use 22
Now using node v22.22.0 (npm v10.9.4)
To set a default version that persists across terminal sessions:
nvm alias default 24
View all installed versions and see which is currently active:
nvm ls
-> v22.22.0
v24.14.0
default -> 24 (-> v24.14.0)
node -> stable (-> v24.14.0) (default)
stable -> 24.14 (-> v24.14.0) (default)
lts/* -> lts/krypton (-> v24.14.0)
To pin a Node.js version per project, create a
.nvmrcfile containing the major version number (for example,24) in the project root. Runningnvm usein that directory auto-switches to the pinned version.
Update Node.js on Ubuntu
Use the update path that matches your installation method so you do not mix package sources.
Update Ubuntu Repository Node.js Packages
If you installed Node.js from Ubuntu repositories, upgrade nodejs and npm together:
sudo apt update
sudo apt install --only-upgrade nodejs npm
Verify installed versions:
node --version
npm --version
# Example on Ubuntu 26.04 LTS v22.22.0 9.2.0
The reported version depends on your Ubuntu release. Refer to the default version table in Method 1 for the expected output on each release.
Update NodeSource Node.js Packages
For NodeSource installs, rewrite the repository file with your target major line, then upgrade:
NODE_MAJOR=24
cat <<EOF | sudo tee /etc/apt/sources.list.d/nodesource.sources
Types: deb
URIs: https://deb.nodesource.com/node_$NODE_MAJOR.x
Suites: nodistro
Components: main
Signed-By: /etc/apt/keyrings/nodesource.gpg
EOF
sudo apt update
sudo apt install --only-upgrade nodejs
Confirm APT is using the NodeSource candidate:
apt-cache policy nodejs | sed -n '1,8p'
nodejs:
Installed: 24.14.0-1nodesource1
Candidate: 24.14.0-1nodesource1
Version table:
*** 24.14.0-1nodesource1 500
500 https://deb.nodesource.com/node_24.x nodistro/main amd64 Packages
Update Node.js with NVM on Ubuntu
NVM upgrades by installing the target version and switching aliases:
source ~/.nvm/nvm.sh
nvm install 24
nvm alias default 24
nvm use 24
Now using node v24.14.0 (npm v11.9.0) default -> 24 (-> v24.14.0)
Troubleshoot Node.js on Ubuntu
Most Node.js setup issues on Ubuntu come from shell initialization, npm prefix permissions, or NodeSource key and repository validation.
Fix “Command Not Found” After NVM Installation on Ubuntu
If you see this after running the installer:
nvm: command not found
Your current shell has not loaded the NVM initialization lines yet. Reload the right shell profile:
source ~/.bashrc
For Zsh users, source the Zsh configuration instead:
source ~/.zshrc
Verify that nvm is now available:
command -v nvm
nvm
Fix Permission Denied During Global npm Install on Ubuntu
If global npm installs fail with an error like this:
npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/lib/node_modules
Check your current npm prefix:
npm config get prefix
/usr
If it points to a system directory, set a user-writable prefix:
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Verify the updated prefix:
npm config get prefix
/home/your-user/.npm-global
NVM also avoids this issue because it installs packages into user-owned paths by default.
Fix NodeSource Repository Key Errors on Ubuntu
If apt update shows errors such as:
W: GPG error: https://deb.nodesource.com/node_24.x nodistro InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 2F59B5F99B1BE0B4 E: The repository 'https://deb.nodesource.com/node_24.x nodistro InRelease' is not signed.
First confirm the key file exists:
ls -l /etc/apt/keyrings/nodesource.gpg
-rw-r--r-- 1 root root 2794 Dec 17 12:00 /etc/apt/keyrings/nodesource.gpg
If the file is missing or corrupted, re-import the key and refresh APT metadata:
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor --batch --yes -o /etc/apt/keyrings/nodesource.gpg
sudo apt update
Hit:1 https://deb.nodesource.com/node_24.x nodistro InRelease Reading package lists... Done
If curl is missing on minimal installs, install it first with sudo apt install -y curl ca-certificates and then repeat the key import.
Remove Node.js from Ubuntu
The removal process depends on which installation method you used.
Remove Node.js Installed via APT
For the Ubuntu repository, remove both packages since they are installed separately:
sudo apt remove --purge -y nodejs npm
sudo apt autoremove -y
Optionally remove the npm cache directory from your home folder:
rm -rf ~/.npm
For a NodeSource installation, npm is bundled in nodejs, so only one package needs removing. Also clean up the repository files:
sudo apt remove --purge -y nodejs
sudo apt autoremove -y
sudo rm -f /etc/apt/sources.list.d/nodesource.sources
sudo rm -f /etc/apt/keyrings/nodesource.gpg
sudo apt update
Remove the npm cache directory:
rm -rf ~/.npm
Confirm Node.js is removed from the system:
apt-cache policy nodejs
node --version
nodejs:
Installed: (none)
Candidate: 22.22.0+dfsg+~cs22.19.6-1ubuntu2
Version table:
22.22.0+dfsg+~cs22.19.6-1ubuntu2 500
500 http://archive.ubuntu.com/ubuntu resolute/universe amd64 Packages
bash: node: command not found
Remove Node.js Installed via NVM
When using NVM, you can remove individual Node.js versions or uninstall NVM entirely.
source ~/.nvm/nvm.sh
nvm current
Deactivate the current version before removing it:
nvm deactivate
nvm uninstall 24
To completely remove NVM and all installed Node.js versions, delete the NVM directory:
The next command permanently deletes NVM and every Node.js version installed through it, including globally installed npm packages under the NVM tree.
rm -rf ~/.nvm
rm -rf ~/.npm
Remove the NVM initialization block from ~/.bashrc (and ~/.zshrc if you use Zsh). Open the file and delete the three lines that begin with export NVM_DIR= and load nvm.sh:
nano ~/.bashrc
Find and delete the block that looks like this:
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Save and close the file, then reload the shell configuration:
source ~/.bashrc
Confirm NVM and Node.js are no longer available:
command -v nvm
node --version
bash: node: command not found
Frequently Asked Questions
Ubuntu 22.04 ships Node.js 12 by default, which is end-of-life and not recommended for new projects. Install a supported release with NodeSource and set NODE_MAJOR=24 for the current Active LTS, or use NVM for per-project version switching. Both methods work identically on Ubuntu 22.04, 24.04, and 26.04.
npm is bundled with Node.js on NodeSource and NVM installations, so installing nodejs from either source includes npm automatically. On the Ubuntu repository, npm is a separate package: run sudo apt install nodejs npm to get both. Check the installed version with npm --version.
LTS stands for Long-Term Support. Even-numbered Node.js majors (20, 22, 24) move through Active LTS, Maintenance LTS, and then end-of-life. Node.js 24 (Krypton) is the current Active LTS and the recommended choice for new projects. Check the Node.js release schedule for current support dates.
Ubuntu 26.04 includes Node.js 22.x, Ubuntu 24.04 includes Node.js 18.x, and Ubuntu 22.04 includes Node.js 12.x. Node.js 18 and 12 are both upstream end-of-life, so use NodeSource or NVM on 22.04 and 24.04 when you need a supported runtime.
Set NODE_MAJOR=22 in the NodeSource .sources file, then run sudo apt update and sudo apt install -y nodejs. This installs the latest Node.js 22 package with npm bundled.
For Ubuntu repository installs, run sudo apt update and sudo apt install --only-upgrade nodejs npm. For NodeSource installs, update NODE_MAJOR in /etc/apt/sources.list.d/nodesource.sources, then run sudo apt update and sudo apt install --only-upgrade nodejs. For NVM, run nvm install 24, nvm alias default 24, and nvm use 24.
No. NodeSource bundles npm inside the nodejs package. Installing sudo apt install -y nodejs from NodeSource gives you both the runtime and npm. Ubuntu repositories split nodejs and npm into separate packages.
This usually means APT could not validate the NodeSource key and installed Ubuntu’s default nodejs package instead. Re-import the key, run sudo apt update, then confirm apt-cache policy nodejs shows a NodeSource candidate before reinstalling nodejs.
Conclusion
After you install Node.js on Ubuntu, the runtime, npm, and your chosen version management approach are ready for production or development use. From here, install TypeScript on Ubuntu for type-safe builds, install Git on Ubuntu for version control, install Yarn on Ubuntu as an npm alternative, or install Docker on Ubuntu for containerized deployments.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>