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
We 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 https://deb.nodesource.com/setup_19.x | 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
v19.0.0