Ubuntu how to upgrade Node.js
By Flavio Copes
Learn how to upgrade Node.js on Ubuntu with a current NodeSource LTS repository, while checking the setup script before running it as root.
I was running a Node service on Ubuntu and I was stuck on an old Node.js version.
For a server, first choose a supported Node.js release. I normally use the current LTS line rather than the newest Current release.
At the time of this update, Node.js 24 is the LTS line. Download the NodeSource setup script, inspect it, then run it:
curl -fsSL https://deb.nodesource.com/setup_24.x -o /tmp/nodesource_setup.sh
less /tmp/nodesource_setup.sh
sudo -E bash /tmp/nodesource_setup.sh
sudo apt install nodejs
Verify both executables after the upgrade:
node --version
npm --version
Do not guess the version number. Check the Node.js releases page and NodeSource’s current installation instructions first. Old release lines stop receiving security fixes.
If you only need Node.js for development on your own machine, a version manager is usually more convenient because it lets projects use different Node.js versions without changing the system package.
To figure out which Node.js version you actually need for a given feature, I built a free Node versions tool.
Related posts about node: