How to install Node.js on Ubuntu 24.04

Three ways to install Node.js on Ubuntu 24.04, NodeSource, nvm and Ubuntu's own package, which one to pick, and how to update or switch versions later.

Tested on Ubuntu 24.04 LTS

Before you start

  • A server running Ubuntu 24.04
  • Root or a user with sudo

To install Node.js on Ubuntu 24.04 for a server, add NodeSource's repository with its setup_lts.x script and run sudo apt install nodejs: you get the current LTS release, and apt upgrade keeps it patched. If you need several Node.js versions side by side (one per project, or to test an upgrade), use nvm instead; Ubuntu's own nodejs package is Node.js 18, which is past its end of life.

Which method to pick

Method Version on 21 October 2026 Updates Best for
NodeSource repository v24.22.1 (LTS) apt upgrade, with the rest of the system Servers running one Node.js version
nvm any, here v24.22.1 nvm install per version, by hand Developers, several versions per server
Ubuntu's nodejs package 18.19.1 Ubuntu's archive (universe) Tools that only need some Node.js

NodeSource builds the official Node.js releases as .deb packages, so the binary is installed system-wide in /usr/bin/node, works for every user, systemd services and PM2, and updates like any other package. nvm installs Node.js into one user's home directory, which is convenient on a laptop and awkward for services that run as another user.

Node.js 18 reached its end of life in April 2025 and gets no more fixes from the Node.js project, and many current packages refuse to install on it. Use it only if something else on the server depends on it.

Install Node.js from NodeSource

Download NodeSource's setup script, look it over, and run it. It adds the repository and its signing key:

bash
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
less nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install -y nodejs

setup_lts.x follows the current LTS line; on 21 October 2026 that was Node.js 24. To pin a major version instead, use its script, for example setup_22.x or setup_24.x. The script writes /etc/apt/sources.list.d/nodesource.sources, which names the version line it chose.

Check it worked:

bash
node -v
npm -v
text
v24.22.1
11.19.1

The nodejs package from NodeSource includes npm and npx, so you don't need Ubuntu's separate npm package.

Some npm packages compile native code when they install. If an install fails with gyp ERR!, add the compiler tools:

bash
sudo apt install -y build-essential

Install Node.js with nvm

nvm (Node Version Manager) is a shell script that downloads Node.js builds into ~/.nvm. Install it as the user who will run Node.js, not as root. Check the nvm releases page for the current version; on 21 October 2026 it was v0.40.8:

bash
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh -o install-nvm.sh
less install-nvm.sh
bash install-nvm.sh

The script adds three lines to ~/.bashrc. Load them in the current shell, then install the latest LTS release:

bash
source ~/.bashrc
nvm install --lts

Check it worked:

bash
node -v
nvm ls

nvm ls lists the installed versions and the default alias, which new shells use. Install and switch to other versions as you need them:

bash
nvm install 22
nvm use 22
nvm alias default 24

A project can pin its version in a .nvmrc file (containing, for example, 24); nvm use in that directory then picks it.

nvm only works in interactive shells that load ~/.bashrc. A systemd service or cron job doesn't see node unless you give it the full path, such as /home/deploy/.nvm/versions/node/v24.22.1/bin/node, which changes with every upgrade. That's the main reason to prefer NodeSource on servers.

Install Ubuntu's package

If a tool just needs some Node.js and you'd rather stay within Ubuntu's archive:

bash
sudo apt install -y nodejs npm
node -v

This prints v18.19.1. It comes from Ubuntu's universe component, which Canonical doesn't guarantee security fixes for unless you have Ubuntu Pro.

Update Node.js

  • NodeSource: sudo apt update && sudo apt upgrade brings the newest release within your major version. To move to a new major version, run that version's setup script (for example setup_26.x once it exists) and sudo apt install nodejs again.
  • nvm: nvm install --lts --reinstall-packages-from=current installs the newest LTS release and copies your global npm packages across. Old versions stay until you nvm uninstall them.

After a major upgrade, reinstall your apps' dependencies (npm ci), because packages with native code are built for one Node.js version.

Troubleshooting

node: command not found right after nvm install. The shell hasn't loaded nvm. Run source ~/.bashrc, or open a new SSH session.

apt wants to remove 100 or more packages when you install NodeSource's Node.js. That's expected if Ubuntu's nodejs and npm were installed first: apt replaces nodejs and removes Ubuntu's npm with the node-* libraries it depended on, since NodeSource's package brings its own npm. Let it, then clear up with sudo apt autoremove.

npm error code EACCES when installing a global package. With NodeSource's Node.js, global packages go to /usr/lib/node_modules, which needs sudo npm install -g. Never use sudo with nvm's npm; it installs into your home directory already.

apt still offers v18 after the setup script. The script didn't finish. Run it again and read its output, and check that apt-cache policy nodejs lists deb.nodesource.com with a higher priority than the Ubuntu archive.

Next steps

Be first when orders open

Join the waitlist and we'll send you one email when VPSNine launches. Pick a plan if you already know which one you want, and we'll size the first servers around it.

  • One email, on launch day
  • Monthly or yearly, no lock-in
  • 14-day money-back guarantee