First, Find How Node.js Was Installed
node -v
npm -v
which node
- A path in /usr/bin: installed with apt, from the distribution or from the NodeSource repository.
apt-cache policy nodejsshows which repository it came from. - A path under ~/.nvm: installed with nvm for that user only.
- A path in /usr/local/bin: installed by hand or with another tool. Upgrade it with that same tool.
Mixing routes leaves two copies, and the one that runs depends on your PATH. Stay with the route you have, or remove the old copy before switching.
Pick the Target Version
Servers should run a long-term support (LTS) line. The release page on nodejs.org lists which lines are in Active LTS or Maintenance and when each one ends. In November 2026, 26 is the Active LTS line and 22 and 24 are in Maintenance. The examples below use 26 as an example major version; replace it with the line you choose. A new major version can change behavior, so read its changelog and test your app on a copy before upgrading production.
Update with nvm
Run these as the user who owns the nvm installation, without sudo:
nvm ls
nvm install --reinstall-packages-from=current 'lts/*'
nvm alias default 'lts/*'
node -v
The second line installs the newest LTS release and reinstalls the global packages of the version you were using. The old version stays installed; remove it later with nvm uninstall and its version number.
Update from the NodeSource Repository
A patch release within the same major arrives with normal updates:
sudo apt update
sudo apt install --only-upgrade nodejs
A new major version needs the repository for that major. Download the NodeSource setup script for it, read it, then run it, and install again:
curl -fsSLo nodesource_setup.sh https://deb.nodesource.com/setup_26.x
less nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
The script removes the old NodeSource repository entry and writes the one for the new major. A third-party repository can install anything as root, so keep the trust you place in it in mind.
Update the Distribution Package
sudo apt update followed by sudo apt upgrade brings security fixes for the distribution's Node.js, but never a new major version within the same release. If you need a newer line, change routes: remove the distribution packages with sudo apt remove nodejs npm, then follow how to install Node.js on Ubuntu. On AlmaLinux and Rocky Linux 9, dnf module list nodejs shows the Node.js lines offered as module streams. Release 10 has no module streams; newer lines come as separately named packages such as nodejs24, which dnf list 'nodejs*' shows.
Global npm Packages and Native Modules
Record your global tools before a major upgrade:
npm ls -g --depth=0
With nvm each version has its own global packages, so reinstall any the upgrade did not carry over. Packages with native code are built for one Node.js version; in each project, reinstall the dependencies with npm ci, which removes node_modules and installs again from the lock file.
Restart the Application
Running processes keep the old Node.js until they restart.
- pm2: run
pm2 update, which saves the process list, restarts the pm2 daemon on the new Node.js, and brings the apps back. Under nvm, install pm2 again in the new version first. If pm2 starts at boot, runpm2 unstartupand thenpm2 startupso the boot script uses the new Node.js. - systemd: run
sudo systemctl restart myapp. If the unit'sExecStartline names an nvm path, that path contains the version number; update it. See systemd unit files.
Check the Result
Run node -v as the user the app runs as, then watch the app's log for startup errors with pm2 logs or journalctl -u myapp -f. To go back under nvm, run nvm use with the old version; with apt, restore the snapshot you took first; see snapshot vs backup. If the app does not come back, find out whether its process is running with the tools in how to list processes in Linux.