By default, Ubuntu 20.04 LTS comes with Node.js 10.19.0. This is quite old, and you may want to upgrade to a newer version. This guide will show you how to upgrade to Node.js 18.
It’s also worth noting that the latest LTS version of Ubuntu is 22.04.4 LTS! You may want to consider upgrading to the latest LTS version of Ubuntu also, but that’s not covered in this guide.
First get the system up to date
The following commands will update the package list and upgrade all installed packages to the latest version,
and also install curl
if it’s not already installed.
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install -y curl
Install Node.js 18
Now lets add the custom repository for Node.js 18 and install it.
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
$ sudo apt-get install -y nodejs
Let’s check the version of Node.js
$ node -v
v18.0.0
That’s it! You have successfully upgraded Node.js to version 18.
NOTE: Other versions of Node.js are available, such as the latest version, or the latest LTS version. You can find the installation instructions for these versions on the NodeSource website.