How to install Node.js on Ubuntu 24
To install Node.js on Ubuntu you have three options: Ubuntu’s own package, NodeSource’s repository or nvm. The first is the easiest but old, so for real work people pick one of the other two. This guide is for Ubuntu 24.04 and 22.04. npm comes with Node.js in both of the recommended ways.
Why not the Node.js from Ubuntu’s repository
Ubuntu’s own nodejs and npm packages work, but Ubuntu keeps one version for the life of the release: Node.js 18 on Ubuntu 24.04 and Node.js 12 on 22.04. Both are past their end of life at nodejs.org, and many current packages refuse to run on them. In Ubuntu, npm is even a separate package.
If Node.js from Ubuntu is already installed, remove it before you switch, so the packages don’t clash:
sudo apt remove nodejs npm libnode-devInstall Node.js on Ubuntu from NodeSource
NodeSource builds Node.js packages for Ubuntu and keeps them up to date. Its script adds the repository and its key, then Node.js installs with apt and updates with the system. setup_lts.x takes the current LTS line. For a fixed major version use setup_24.x or setup_22.x instead.
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs
node -v
npm -vThe script is saved to a file first, so you can read it before you run it:
less nodesource_setup.shThis nodejs package already contains npm. node prints its version, for example v24.22.0.
Native npm modules that compile C++ code need build tools: sudo apt install -y build-essential
Install Node.js with nvm
nvm installs Node.js into your home folder, without sudo, and switches between versions per project. It suits a developer machine where different projects need different Node.js. The install command is from the nvm README. It clones nvm into ~/.nvm and adds a few lines to ~/.bashrc.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash
source ~/.bashrc
nvm install --lts
node -v
npm -vInstall another version next to it, switch to it and choose the one new terminals start with:
nvm install 22
nvm use 22
nvm alias default 24
nvm lsWith a .nvmrc file holding a version number in the project folder, this is enough there:
nvm useWhich Node.js and npm are you running
With several installs it is easy to run a different Node.js than you think. These commands show the version and where it comes from:
node -v
npm -v
which node/usr/bin/node is the apt package (NodeSource or Ubuntu). A path inside ~/.nvm/versions/ is nvm. nvm is set up for your own user only, so under sudo Node.js is still the system one, or none at all.
If Node.js doesn’t install or run
nvm: command not foundright after installing nvm: the current terminal hasn’t read~/.bashrcyet. Close it and open a new one, or run:source ~/.bashrctrying to overwrite '/usr/include/node/common.gypi', which is also in package libnode-dev: Node.js from Ubuntu is still installed. Remove it with:sudo apt remove nodejs libnode-devThen install Node.js again:sudo apt install -y nodejs- An
EACCESerror when npm installs a global package (-g): global packages go to a system folder that belongs to root. Don’t run npm withsudoand don’t change the folder’s rights. Use nvm, or add~/.local/bintoPATHin~/.profileand point npm to your home folder:npm config set prefix ~/.local - A package says your Node.js is too old (
Unsupported engineorSyntaxErrorin its code): check the version:node -vYou are probably still on Ubuntu’s Node.js 18 or 12.
If you also work on a Mac

System Junk in MacWashing finds the caches of every app it knows, including those hidden inside app data, plus logs, Xcode junk and leftovers of deleted apps. It shows how much each takes and clears them in one go. Anything debatable stays unchecked until you decide.
Free trial · macOS 14 or later
Questions and answers
How do I install Node.js on Ubuntu?
For a server, use the NodeSource repository: run its setup_lts.x script, then install the nodejs package with apt. On a developer machine nvm is handier: nvm install --lts Both come with npm.
Which Node.js version should I install?
The current LTS line. In October 2026 that is Node.js 24, and Node.js 26 becomes LTS at the end of the month. Odd-numbered releases are short-lived and not meant for production.
How do I update Node.js?
From NodeSource, with the system: sudo apt update && sudo apt upgrade To move to a new major version, run that version’s setup script. With nvm, this installs the newest LTS next to the old one: nvm install --lts