Guides · Server software · updated 3 Dec 2026
How to upgrade Node.js to the current LTS on a server running pm2 apps
Every Node.js release line reaches end of life, after which it receives no security fixes. Upgrading is mostly painless, with two exceptions: apps that declare a Node version range, and native modules that must be rebuilt for the new version.
Find what runs on which Node version
pm2 shows the apps; each app's package.json may declare the versions it supports.
node -v pm2 list jq .engines package.json # in each app's folderCheck for native modules
Packages with compiled code (bcrypt, sharp, sqlite3, canvas) must be rebuilt after a major Node upgrade.
find node_modules -name '*.node' -o -name binding.gyp 2>/dev/null | headInstall the new LTS
Using the NodeSource repository; the setup script switches the repository, and the package upgrade replaces the binary.
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs node -vRebuild each app
Reinstall from the lock file so native modules are compiled for the new version, then run the tests if there are any.
cd /path/to/app && rm -rf node_modules && npm ciRefresh pm2 and the startup unit
The pm2 daemon keeps running on the old Node until it is updated.
pm2 update pm2 restart all --update-env pm2 save # re-run the pm2 startup command so the unit uses the new node pathVerify
Each app should answer and the logs should be quiet.
pm2 list pm2 logs --lines 20 --nostream curl -sI http://127.0.0.1:PORT | head -n 1
Common mistakes
- Skipping npm ci: the app starts and then crashes on the first call to a native module.
- Services that run node outside pm2 (systemd units) keep the old binary until restarted.
- Upgrading two major versions at once: go to the next LTS first if the app is old.
How to undo it
Install the previous major version from the NodeSource repository for that version, rebuild with npm ci, and restart the apps. Keep the old package-lock.json.
Sources
Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.