How to install Node.js 18 on Ubuntu 20.04 LTS

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 don’t like to upgrade to a new version of just about
anything until it’s 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 getting 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.

System updates and dependency installation

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 don’t 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

sudo apt install -y curl

Installing Node.js 18 on Ubuntu

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 update 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 that’s finished running, we can check that we are in fact running the
latest and greatest version of Node.js:

$ node --version

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.

Looking for an Ubuntu host?

Check out DigitalOcean, with $200 of free credit to spend over 2 months, you can explore Ubuntu on their Droplets and all of their other managed services!

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

If you found this article helpful, please consider buying me a coffee.