How to install Node.js 18 on Ubuntu 20.04 LTS by Josh Sherman


It’s that time of year again, for not just a new version of Node.js, but for a new version of Ubuntu as well! Sadly though, my preferred method of installing Node.js on Ubuntu isn’t quite ready for Ubuntu 22.04 LTS.

That’s okay though, I do not like to upgrade to a new version of just about / anything / until it had enough time to percolate and have the early release bugs sorted out.

So with that being said, today we’re going to install Node.js 18, which is the new “current” version, on ol ‘reliable of the past 2 years, Ubuntu 20.04 LTS.

Keep in mind that Ubuntu 22.04 LTS is shipping with Node.js 12, which is to be expected due to Debian / Debian-based distros focus on stability. If you are trying to use Ubuntu 22.04 LTS, your best bet is to give nvm a spin if you are in need of the latest version of Node.js.

I’ve mentioned this previously, nvm is more than sufficient to get the latest version (or different versions) of Node.js running on your machine. I personally avoid this in production environments, as I much prefer relying on the system’s package manager to do all of my upgrades, instead of having to remember multiple package / version managers.

This is the same logic that keeps me from compiling software if at all possible.

All that being said, I always like to start by making sure my system is 100% up to date (rebooting if necessary):

sudo apt update
sudo apt upgrade

Also, if you do not already have curl installed, it’s a good time to do that as well, since we’ll be using that to download the installation script from NodeSource:

With our system up to date and our dependencies in check, let’s grab the setup script for Node.js 18 and give it a spin:

curl -fsSL | sudo -E bash -

The provided script will add in some new apt sources and even runs apt
to ensure we have our cache primed and ready to rock!

Once the script is done running, you can install or upgrade to Node.js 18:

sudo apt install -y nodejs

And once thats finished running, we can check that we are in fact running the latest and greatest version of Node.js:

If you ARE NOT running the latest version of Node.js at this point, double check the output of the previous commands, as more than likely one of them spit out an error that may need to be addressed.

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.



Please enter your comment!
Please enter your name here