How to install Node.js 19 on Ubuntu 20.04 LTS

Periodically, I check my site analytics to see which posts are getting the most
traffic. It never ceases to amaze me at how many posts documenting older
versions of Ubuntu, as far back as 16.04 LTS, still receive regular traffic.

While they may not be evergreen forever, there’s something to be said
about explicitly targeting these older versions in your content.

Just because a new version of Ubuntu drops, currently LTS version 22.04, that
doesn’t mean everybody is in a hurry to upgrade to it. With older versions
receiving active security updates for five or more years, and the burden associated with a full system upgrade, it makes sense that many will “set it and forget it” for as long as possible.

That said, even if you plan to commit to your underlying operating system’s
version, doesn’t mean you want to make the same sacrifice with your actual
development stack. There are still many strides being made with Node.js with
every new version, so the need to be able to install a newer version on an older
version of Ubuntu is extremely relevant.

There’s a good chance you’re here because you’re actually interested in installing Node.js 19.x on Ubuntu 20.04 LTS, and not just here to listen to be
pontificate about versioning and upgrade cycles.

Sad, but worth mentioning, if you’re interested in installing the latest Node.js
version on an even older Ubuntu release (like 18.04 LTS or prior) it’s probably
about time for you to upgrade. There are now some dependency issues with the GNU C Library that will cause you some grief.

All right, so Node.js 19 on Ubuntu 20.04 LTS (and 22.04 LTS), let’s get to it!

Keep in mind, you can always use nvm to accomplish what I’m about to outline,
but that’s not my preferred method of installation of Node.js. The reason I prefer to install it by way of an apt source, is because that’s one less thing I have to worry about upgrading manually. One less thing to worry about is one
less thing to potentially forget, and that’s a good thing.

First and foremost, it’s always good to make sure your system is up date to
date, rebooting it if necessary:

sudo apt update
sudo apt upgrade

This guide expects curl to already be installed as well:

sudo apt install -y curl

This guide also makes reference of sudo, which you may not have available if
you’re running inside of a Docker container. If that’s the case, just omit the
sudo commands and you should be just find.

With everything up to date and the necessary dependencies installed, we can
fetch the Node.js 19.x installation script with curl and run it:

curl -fsSL | sudo -E bash -

This script will do all of the necessary work to add the new apt source and
run an apt update to get things primed and ready.

What it doesn’t do, is actually installed the nodejs package for you, so
you’ll also need to run:

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.

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.