Ubuntu’s default Node.js package is convenient, but it is not always the runtime modern JavaScript projects expect. To install Node.js on Ubuntu, choose between the Ubuntu repository, NodeSource’s APT repository, or NVM, depending on whether you want distro-managed stability, a current upstream LTS line, or per-project version switching.
The commands target Ubuntu 26.04 LTS (Resolute Raccoon), 24.04 LTS (Noble Numbat), and 22.04 LTS (Jammy Jellyfish). NodeSource and NVM include npm with Node.js, while Ubuntu’s repository method installs the separate npm package when you need npm commands.
Install Node.js on Ubuntu
Compare the three methods before choosing one package source:
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| Ubuntu Repository | Ubuntu universe | Release default: 22.x on 26.04, 18.x on 24.04, 12.x on 22.04 | Automatic with apt upgrade | Conservative baseline installs and compatibility checks |
| NodeSource Repository | NodeSource | Active LTS, Maintenance LTS, or Current release | Automatic with apt upgrade | Most projects that need a supported upstream Node.js line |
| Node Version Manager (NVM) | NVM GitHub | Any supported Node.js release | Manual with nvm install | Per-project version switching without system packages |
Use one method unless you deliberately need both a system Node.js package and an NVM-managed project runtime. Mixing APT packages, NodeSource packages, and NVM paths without checking command -v node can make upgrades and troubleshooting harder.
These instructions cover Ubuntu 26.04 LTS (Resolute Raccoon), 24.04 LTS (Noble Numbat), and 22.04 LTS (Jammy Jellyfish).
The NodeSource and NVM sections use the same commands across all supported releases. The Ubuntu repository section uses the same install command, but the default Node.js and npm versions depend on your Ubuntu release.
Before installing, update the package index and apply any pending security updates:
sudo apt update && sudo apt upgrade -y
The -y flag accepts APT prompts automatically. Omit it when you want to review package changes before confirming.
New to sudo? See the guide on adding a user to sudoers on Ubuntu before continuing.
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. The packages are available from Ubuntu’s universe component, so enable the Ubuntu universe repository first if your system does not already have it enabled.
Default Node.js Versions in Ubuntu Repositories
| Ubuntu Release | Default nodejs | Default npm | Upstream Status |
|---|---|---|---|
| Ubuntu 26.04 LTS (Resolute) | 22.22.1+dfsg+~cs22.19.15-1ubuntu1 | 9.2.0~ds3-1 | Maintenance LTS |
| Ubuntu 24.04 LTS (Noble) | 18.19.1+dfsg-6ubuntu5 | 9.2.0~ds1-2 | End-of-life |
| Ubuntu 22.04 LTS (Jammy) | 12.22.9~dfsg-1ubuntu3.6 | 8.5.1~ds-1 | 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.1 9.2.0 # Ubuntu 24.04 LTS v18.19.1 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 24.04’s default Node.js package is Node.js 18, not Node.js 22. Use NodeSource with
NODE_MAJOR=22or NVM withnvm install 22when a project specifically needs Node.js 22 on Ubuntu 24.04. Ubuntu 22.04 ships Node.js 12, which is also end-of-life upstream. See the official Node.js end-of-life schedule for lifecycle details.
Install Node.js from NodeSource Repository on Ubuntu
NodeSource publishes dedicated Node.js APT packages for supported major release lines, so you can install Node.js 22, Node.js 24, or the current Node.js 26 line and receive upstream updates outside Ubuntu’s default package cadence.
If you see setup_24.x, setup_22.x, or setup_lts.x examples elsewhere, those are NodeSource bootstrap scripts for the same repository family. The manual DEB822 setup in this section keeps the nodistro suite, architecture filter, and keyring path visible before APT trusts the source.
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 system keyrings directory if it does not exist:
sudo install -m 0755 -d /usr/share/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 /usr/share/keyrings/nodesource.gpg
sudo chmod 644 /usr/share/keyrings/nodesource.gpg
Set NodeSource Node.js Version on Ubuntu
Create the repository configuration file. Set NODE_MAJOR to your target major version, then write the DEB822 source file. NodeSource uses nodistro as a universal suite name that works across all supported Ubuntu releases:
NODE_MAJOR=24
printf '%s\n' \
'Types: deb' \
"URIs: https://deb.nodesource.com/node_${NODE_MAJOR}.x" \
'Suites: nodistro' \
'Components: main' \
"Architectures: $(dpkg --print-architecture)" \
'Signed-By: /usr/share/keyrings/nodesource.gpg' \
| sudo tee /etc/apt/sources.list.d/nodesource.sources > /dev/null
Choose the Node.js major line that matches your project’s support target:
NODE_MAJOR=22: Maintenance LTS (Jod)NODE_MAJOR=24: Active LTS (Krypton), recommended for most new projectsNODE_MAJOR=26: Current release, useful for testing the next major line before it enters LTS
For Node.js 22 on Ubuntu 24.04, set NODE_MAJOR=22 before writing the NodeSource source file, then run apt update and apt install. NodeSource currently publishes Node.js 22 packages for Ubuntu through the same nodistro repository path.
Node.js 24 (Krypton) is the current Active LTS release and recommended for most new projects. Choose Node.js 22 only when your project is pinned to that LTS line, and avoid Node.js 20 or older for new work because upstream support has ended. 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
# Relevant output Hit:1 https://deb.nodesource.com/node_24.x nodistro 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.15.0-1nodesource1
Version table:
24.15.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.x.x 11.x.x
Install Node.js with Node Version Manager (NVM) on Ubuntu
NVM installs Node.js into your home directory and keeps each version isolated. After the root-owned downloader prerequisites are installed, the NVM and Node.js commands run as your normal user on Ubuntu 26.04, 24.04, and 22.04.
Install NVM on Ubuntu 26.04, 24.04, and 22.04
NVM is a shell function, not a system binary. Install curl, CA certificates, and jq so the installer can resolve the latest NVM release from GitHub before it runs:
sudo apt install -y curl ca-certificates jq
Resolve the latest NVM release tag through the GitHub API, then run the matching installer script:
NVM_VERSION=$(curl -fsSL https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r '.tag_name')
if [ -n "$NVM_VERSION" ] && [ "$NVM_VERSION" != "null" ]; then
curl -fsSL "https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh" | bash
else
printf '%s\n' 'Unable to resolve latest NVM release from GitHub.' >&2
fi
The installer appends the permanent NVM initialization block to your shell profile. Load NVM into the current terminal with the installed nvm.sh path, or open a new terminal and let the profile block load it automatically:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
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. The directnvm.shsource block works for the current shell even when your profile file is not loaded yet.
List Available Node.js Versions with NVM
View all available Node.js versions:
nvm ls-remote
LTS releases are marked with their codenames, such as Jod and Krypton. To show only LTS versions:
nvm ls-remote --lts
Install a Node.js Version with NVM on Ubuntu
Install the default LTS alias and its bundled npm release:
nvm install --lts
Alternatively, install a specific version by number:
nvm install 24
Downloading and installing node v24.x.x... ######################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v24.x.x (npm v11.x.x)
node --version
npm --version
v24.x.x 11.x.x
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.x.x (npm v10.x.x)
To set the latest LTS line as the default for future terminal sessions:
nvm alias default 'lts/*'
View all installed versions and see which is currently active:
nvm ls
-> v22.x.x
v24.x.x
default -> lts/* (-> v24.x.x)
node -> stable (-> v24.x.x) (default)
stable -> 24.x (-> v24.x.x) (default)
lts/* -> lts/krypton (-> v24.x.x)
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.
Use Node.js on Ubuntu
After installing Node.js, create a small project directory to confirm both node and npm work in the same shell:
mkdir -p ~/nodejs-test
cd ~/nodejs-test
npm init -y
printf '%s\n' 'console.log("Hello from Node.js");' > app.js
node app.js
Hello from Node.js
Use npm for normal dependency installs unless your project already declares a different package manager. For projects that rely on a separate lockfile or package-manager policy, use the dedicated setup paths for Yarn on Ubuntu or pnpm on Ubuntu.
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.1 9.2.0
The reported version depends on your Ubuntu release. Use the default version table in the Ubuntu repository section 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
printf '%s\n' \
'Types: deb' \
"URIs: https://deb.nodesource.com/node_${NODE_MAJOR}.x" \
'Suites: nodistro' \
'Components: main' \
"Architectures: $(dpkg --print-architecture)" \
'Signed-By: /usr/share/keyrings/nodesource.gpg' \
| sudo tee /etc/apt/sources.list.d/nodesource.sources > /dev/null
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.15.0-1nodesource1
Candidate: 24.15.0-1nodesource1
Version table:
*** 24.15.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 current LTS release and keeping the default alias pointed at the LTS line:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install --lts
nvm alias default 'lts/*'
nvm use --lts
Now using node v24.x.x (npm v11.x.x) default -> lts/* (-> v24.x.x *)
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 NVM yet. Load the installed NVM script directly:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
If NVM works after direct sourcing but not in a new terminal, check whether the installer block exists in your shell profile:
grep -n 'NVM_DIR' ~/.bashrc ~/.zshrc 2>/dev/null
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 "$HOME/.npm-global"
touch ~/.bashrc
grep -qxF 'export PATH="$HOME/.npm-global/bin:$PATH"' ~/.bashrc || printf '%s\n' 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
export PATH="$HOME/.npm-global/bin:$PATH"
Verify the updated prefix:
npm config get prefix
/home/your-user/.npm-global
NVM avoids this issue because it installs packages into user-owned paths by default. Do not apply the custom npm prefix inside an NVM-managed shell; npm config prefix can interfere with version switching.
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 /usr/share/keyrings/nodesource.gpg
-rw-r--r-- 1 root root 2794 Apr 28 12:00 /usr/share/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 /usr/share/keyrings/nodesource.gpg
sudo chmod 644 /usr/share/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.
Fix NodeSource Release File Errors on Ubuntu
If APT reports a missing release file for an Ubuntu codename such as jammy, the NodeSource source file is using the wrong suite name:
E: The repository 'https://deb.nodesource.com/node_22.x jammy Release' does not have a Release file.
Remove the stale source file and recreate it with the NodeSource nodistro suite:
sudo rm -f /etc/apt/sources.list.d/nodesource.list
sudo rm -f /etc/apt/sources.list.d/nodesource.sources
sudo install -m 0755 -d /usr/share/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor --batch --yes -o /usr/share/keyrings/nodesource.gpg
sudo chmod 644 /usr/share/keyrings/nodesource.gpg
NODE_MAJOR=24
printf '%s\n' \
'Types: deb' \
"URIs: https://deb.nodesource.com/node_${NODE_MAJOR}.x" \
'Suites: nodistro' \
'Components: main' \
"Architectures: $(dpkg --print-architecture)" \
'Signed-By: /usr/share/keyrings/nodesource.gpg' \
| sudo tee /etc/apt/sources.list.d/nodesource.sources > /dev/null
sudo apt update
Hit:1 https://deb.nodesource.com/node_24.x nodistro InRelease Reading package lists... Done
Fix NodeSource common.gypi Overwrite Errors on Ubuntu
If you previously installed Ubuntu’s nodejs and npm packages, a leftover libnode-dev package can block NodeSource with an overwrite error like this. The package version may differ, but the conflicting file path is the useful part:
dpkg: error processing archive /var/cache/apt/archives/nodejs_24.15.0-1nodesource1_amd64.deb (--unpack): trying to overwrite '/usr/include/node/common.gypi', which is also in package libnode-dev 12.22.9~dfsg-1ubuntu3.6
Remove the distro Node.js packages and headers before installing NodeSource again:
sudo apt remove --purge -y libnode-dev nodejs npm nodejs-doc
sudo apt autoremove --dry-run
Review the dry-run output. If it lists only Node.js and npm dependencies you no longer need, run the cleanup and then repeat the NodeSource installation:
sudo apt autoremove --purge
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. Preview dependency cleanup before removing leftover packages from a reused desktop or server:
sudo apt remove --purge -y nodejs npm
sudo apt autoremove --dry-run
If the preview lists only Node.js and npm dependencies you no longer need, run the cleanup without forcing -y so you can review APT’s confirmation prompt:
sudo apt autoremove --purge
Optionally remove the current user’s npm cache directory from your home folder. This does not remove project directories:
rm -rf ~/.npm
For a NodeSource installation, npm is bundled in nodejs, so only one package needs removing. Also clean up both current and older NodeSource repository files:
sudo apt remove --purge -y nodejs
sudo rm -f /etc/apt/sources.list.d/nodesource.sources
sudo rm -f /etc/apt/sources.list.d/nodesource.list
sudo rm -f /usr/share/keyrings/nodesource.gpg
sudo rm -f /etc/apt/keyrings/nodesource.gpg
sudo apt update
Remove the current user’s npm cache directory if you do not need cached npm downloads:
rm -rf ~/.npm
Confirm Node.js is no longer installed as a system package. The first command should return no installed ii package lines, and the second should return no node path if no other system package provides it:
dpkg -l nodejs npm | grep '^ii' || true
hash -r
command -v node || true
# No output means the packages and command path are gone.
Remove Node.js Installed via NVM
When using NVM, you can remove individual Node.js versions or uninstall NVM entirely.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm current
If nvm current prints a version, store it before deactivating so you remove the active version rather than a stale example number:
current_node=$(nvm current)
nvm deactivate
nvm uninstall "$current_node"
To completely remove NVM and all installed Node.js versions, delete the NVM directory:
The next commands permanently delete NVM and every Node.js version installed through it, including globally installed npm packages under the NVM tree, and remove the current user’s npm cache.
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 clear the current shell’s NVM function and command cache:
unset -f nvm 2>/dev/null || true
hash -r
Confirm NVM and Node.js are no longer available in the current shell. These checks should return no output unless another system Node.js package is still installed:
command -v nvm
command -v node
# No output means NVM and its Node.js path are gone.
Conclusion
Node.js is installed on Ubuntu from the package source that matches your workflow: Ubuntu’s universe package for a distro-managed baseline, NodeSource for current upstream LTS packages, or NVM for project-level switching. For the next layer of JavaScript tooling, install TypeScript on Ubuntu, scaffold React.js on Ubuntu, or move containerized projects into Docker on Ubuntu.


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>