How to install Node.js 18 on Ubuntu 20.04 LTS

Josh Sherman
2 min read
Servers / Serverless Node.js Debian / Ubuntu

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.

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 NodeSource:

sudo apt install -y curl

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 https://deb.nodesource.com/setup_18.x | 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
v18.0.0

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.

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

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.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles