The latest release of Node.js, which will be LTS later this year, is out. Even if you’re running the shiny new Ubuntu LTS release, you’re already behind. Never fear, it’s very easy to install Node.js 22 via the APT package manager on Ubuntu with a few simple commands.
As mentioned previously, I still very much prefer this method, to using nvm
and other alternative methods. By sticking with apt
, I don’t have to worry about running updates with different tools, and it slides nicely into my existing workflow.
Update your system
It’s good to keep your system up to date, especially when you’re account to install something new. You are probably already familiar with these commands, but if not, here’s how to update and upgrade your Ubuntu system:
% sudo apt update # Update package list
% sudo apt upgrade # Upgrade installed packages
ZshInstall necessary dependencies
There’s a solid chance that you already have these packages on your system, but it’s always worth double checking. Make sure we have the following packages already installed by running this command:
% sudo apt install -y ca-certificates curl gnupg
ZshImport GPG key for the source
With our required packages installed, we’ll go ahead and import the GPG key for NodeSource’s repository:
% sudo mkdir -p /etc/apt/keyrings
% curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
ZshAdd the APT source
Next, we’ll add the APT source for Node.js 22. If you happen to want a different version of Node.js, you can adjust the 22.x
in the echo
statement:
% echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
ZshUpdate and install
With the source repository added, we’re ready to install the package. First, we need to run another update to sync the package list, then we can proceed with installing Node.js 22:
% sudo apt update
% sudo apt install nodejs -y
ZshCheck the version
Finally, depending on how much you trust the computer, you may want to double check that everything went according to plan. You can pass the --version
argument to node
and find out:
% node --version
v22.2.0
ZshUpgrading from a previous version
If you happened to have followed one of my previous posts, and already have Node.js installed, the path to upgrade is even easier:
# This will overwrite a previous value:
% echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
# Then update and upgrade to get the lastest!
% sudo apt update
% sudo apt upgrade
Zsh