Node.js is the server-side JavaScript runtime built on Chrome’s V8 engine. On Ubuntu you can install it from apt (distro nodejs in universe), NodeSource (vendor apt repo for a chosen major), NVM (per-user version switching), or the official linux-x64 tar.xz from nodejs.org. Each path ships node, npm, and usually npx, but they land in different paths and update differently.
This guide covers all four methods on amd64 Ubuntu, with verify steps, a minimal HTTP smoke test, update and uninstall paths, and troubleshooting. Current ranking guides agree on the same split: apt for a single distro build, NodeSource for a pinned system-wide major, NVM when you switch versions per project, and a tarball when you want a fixed upstream binary without adding a repository. Pick one primary method per machine unless you deliberately isolate versions (for example system apt Node plus NVM in your developer account).
Tested on: Ubuntu 26.04 LTS (Resolute Raccoon); kernel 7.0.0-27-generic.
PATH. Stacking NodeSource nodejs, a tarball under /opt, and NVM without careful ordering leads to node --version surprises—run which -a node after every install.
Quick command summary
| Task | Command |
|---|---|
| Install from Ubuntu apt | sudo apt update && sudo apt install -y nodejs npm |
| Install from NodeSource (22.x example) | curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - then sudo apt install -y nodejs |
| Install NVM | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash |
| Install LTS via NVM | nvm install --lts |
| Install from tar.xz | wget https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-x64.tar.xz then extract under /opt/nodejs |
| Check versions | node --version and npm --version |
List all node binaries |
which -a node |
| Switch NVM version | nvm use 22 |
| Remove apt / NodeSource | sudo apt purge -y nodejs npm |
Prerequisites
- Ubuntu 22.04 LTS, 24.04 LTS, 26.04 LTS, or newer on x86_64 (amd64). ARM hosts should use distro
nodejs, NVM arm64 tarballs, or install Node.js on Debian patterns on arm64. - sudo for
apt,/opt, and system-wide symlinks — see apt command. - Outbound HTTPS to
archive.ubuntu.com,deb.nodesource.com,nodejs.org, orraw.githubusercontent.com(NVM), depending on method. - curl or wget for download-based installs.
See check Ubuntu version if you are unsure which release apt should target. For broader CLI reference, see Linux commands.
Choose an install method
| Method | Best for | Jump to |
|---|---|---|
apt install nodejs |
Fast system-wide Node aligned with Ubuntu security updates | Method 1 |
| NodeSource apt repo | Pin a specific major (20, 22, 24) with apt upgrade |
Method 2 |
| NVM | Developers switching Node majors per project | Method 3 |
Official tar.xz |
Air-gapped or fixed upstream binary under /opt without a repo |
Method 4 |
For most tutorials and IDEs, NVM or NodeSource keeps you on a supported LTS. apt is fine when Ubuntu’s packaged major matches your stack.
Method 1: Install Node.js from Ubuntu apt
Ubuntu ships nodejs and npm in the universe component. Enable universe if your image is minimal, refresh indexes, and install:
sudo apt update
sudo apt install -y nodejs npmVerify with the packaged binary (not every node on PATH is the apt build—IDEs and other tools sometimes ship their own):
/usr/bin/node --version
/usr/bin/npm --version
which -a nodev22.22.1
9.2.0
/root/.cursor-server/bin/linux-x64/.../node
/usr/bin/node
/bin/nodeOn Ubuntu 26.04 the packaged major was 22; on 22.04 or 24.04 LTS you may see a different major—always run /usr/bin/node --version after install. Ubuntu’s build may lag the current LTS on nodejs.org but receives distro security maintenance.
apt install nodejs reports no installation candidate, run sudo apt install software-properties-common and sudo add-apt-repository universe, then sudo apt update again.
Method 2: Install Node.js from NodeSource
NodeSource publishes setup scripts that add a signed apt repository for Node 20.x, 22.x, or 24.x. Remove an existing distro nodejs package first so which node does not keep resolving to the older build.
Purge conflicting packages, install prerequisites, and run the setup script (22.x example):
sudo apt purge -y nodejs npm
sudo apt update
sudo apt install -y ca-certificates curl gnupg
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejsVerify:
node --version
npm --version
which nodeAfter a successful setup, node --version should report a 22.x line and npm is bundled with the NodeSource package (no separate npm apt install).
Future updates:
sudo apt update && sudo apt upgrade -y nodejscurl -fsSL https://deb.nodesource.com/setup_22.x failed with SSL certificate verify result: unable to get local issuer certificate (20) before the signing key could be imported. That is an environment trust issue, not a NodeSource script bug—on a normal Ubuntu desktop with current ca-certificates, the script prints repository configuration lines and exits cleanly. Fix corporate TLS interception or refresh CA trust, then rerun the pipe.
Method 3: Install Node.js with NVM
NVM (Node Version Manager) installs multiple Node versions under ~/.nvm and switches what node resolves to in your shell. It is the usual choice when one laptop runs Node 20 for legacy apps and Node 24 for greenfield work.
This article keeps NVM steps short; the full workflow (bash vs zsh, .nvmrc, Snap curl pitfalls) is in install NVM on Ubuntu.
Quick path after cURL and git are installed:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
source ~/.bashrc
command -v nvm
nvm install --lts
node --version
npm --versionnvm
v24.18.0
11.16.0Set a default for new shells:
nvm alias default lts/*Switch versions anytime with nvm use 22 or nvm use 24.
Method 4: Install Node.js from the official tar.xz
Node.js publishes prebuilt linux-x64 archives at nodejs.org/dist. Use this when you want a fixed upstream binary under /opt without NodeSource or NVM—common on servers with strict change control.
Download the tarball
Pick a version from the download page:
cd /tmp
NODE_VER=v22.17.0
wget "https://nodejs.org/dist/${NODE_VER}/node-${NODE_VER}-linux-x64.tar.xz"
ls -lh "node-${NODE_VER}-linux-x64.tar.xz"-rw-r--r-- 1 root root 30M Jun 25 2025 node-v22.17.0-linux-x64.tar.xzInspect contents before extracting:
tar -tf "node-${NODE_VER}-linux-x64.tar.xz" | headnode-v22.17.0-linux-x64/
node-v22.17.0-linux-x64/bin/
node-v22.17.0-linux-x64/bin/node
node-v22.17.0-linux-x64/bin/npm
...Install under /opt and expose binaries
Extract with the tar command and link into /usr/local/bin so node is on default PATH:
sudo mkdir -p /opt/nodejs
sudo tar -xJf "node-${NODE_VER}-linux-x64.tar.xz" -C /opt/nodejs --strip-components=1
sudo ln -sf /opt/nodejs/bin/node /usr/local/bin/node
sudo ln -sf /opt/nodejs/bin/npm /usr/local/bin/npm
sudo ln -sf /opt/nodejs/bin/npx /usr/local/bin/npx
sudo ln -sf /opt/nodejs/bin/corepack /usr/local/bin/corepackVerify:
/usr/local/bin/node --version
/usr/local/bin/npm --version
which nodev22.17.0
10.9.2
/usr/local/bin/nodenodejs, NVM with the matching arch tarball, or the linux-arm64 build from nodejs.org—not linux-x64.
Verify Node.js and npm
Regardless of method, confirm the runtime and package manager:
node --version
npm --version
npx --version
which -a nodeOptional REPL smoke test:
node -e "console.log('Node OK:', process.version)"Node OK: v22.17.0If node is missing or shows an unexpected version, check which command and your PATH—NVM users must source ~/.bashrc or open a new terminal.
Run a minimal HTTP server
Create hello.js:
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello from Node.js on Ubuntu\n');
}).listen(8080, () => console.log('Listening on http://127.0.0.1:8080'));Run it:
node hello.jsIn another terminal:
curl -s http://127.0.0.1:8080/Hello from Node.js on UbuntuStop the server with Ctrl+C. For interactive exploration, see Node.js REPL.
Keep Node.js updated
| Install path | Update command |
|---|---|
| apt | sudo apt update && sudo apt upgrade -y nodejs npm |
| NodeSource | sudo apt update && sudo apt upgrade -y nodejs |
| NVM | nvm install --lts or nvm install 24 then nvm alias default 24 |
| tar.xz | Download newer tarball, re-extract to /opt/nodejs, refresh symlinks |
After any upgrade, re-run node --version and reinstall global npm tools if their majors changed.
Uninstall Node.js
apt or NodeSource
sudo apt purge -y nodejs npm
sudo apt autoremove -yIf you used NodeSource, remove its list file when you no longer want the repo:
sudo rm -f /etc/apt/sources.list.d/nodesource.list
sudo apt updateNVM
nvm uninstall 22
nvm uninstall 24
# when done: rm -rf ~/.nvm and remove NVM block from ~/.bashrcSee install NVM on Ubuntu for the full removal checklist.
tar.xz under /opt
sudo rm -rf /opt/nodejs
sudo rm -f /usr/local/bin/node /usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepackFor mixed installs and orphan cleanup, see remove software on Ubuntu.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
node: command not found |
PATH not loaded (NVM) or symlinks missing (tar.xz) | source ~/.bashrc or recreate /usr/local/bin links |
node --version shows wrong major |
Another node earlier on PATH |
which -a node; call /usr/bin/node or fix NVM default |
E: Unable to locate package nodejs |
Universe disabled or outdated indexes | Enable universe; sudo apt update |
NodeSource curl SSL verify error |
Missing or intercepted CA trust | sudo apt install ca-certificates; fix proxy TLS; retry setup script |
nvm: command not found |
Installer not sourced | source ~/.nvm/nvm.sh or open new terminal |
| Wrong architecture tarball | Downloaded linux-x64 on ARM |
Pick linux-arm64 from nodejs.org or use apt/NVM |
npm very old with apt Node |
Ubuntu pins npm separately from nodejs | Use NodeSource/NVM/tar.xz for bundled npm, or upgrade deliberately |
References
- Node.js — Download
- Node.js — Previous releases
- NodeSource distributions (GitHub)
- nvm-sh/nvm (GitHub)
- Ubuntu packages — nodejs
Summary
Install Node.js on Ubuntu with sudo apt install nodejs npm when the distro major is enough, NodeSource when you need a specific LTS major via apt, NVM when you switch versions per project, or the official linux-x64 tar.xz under /opt when you want a pinned upstream binary without a repository. Verify with node --version, npm --version, and which -a node, then uninstall using the path that matches how you installed.
Next: wire Node into your editor (VS Code, Sublime), or continue with the Node.js tutorial index.

