Skip to main content

Installing Node.js on Ubuntu

This page shows how to install Node.js on an Ubuntu 22 host.

It only shows how to install a single, global Node.js version.

If you need multiple Node.js version support, see this page to work with NVM (Node Version Manager): NVM - Node.js Version Manager

NOTE: If you will need to work with multiple versions of Node.js on the same host, such as performing automated builds of Angular apps for different Angular versions, then these steps won't work for you.
Instead, you need to install NVM to manage those versions of Node.js.

Removing Old Versions

Before installing Node.js, it is necessary to remove any existing version of Node from the host.

Be sure to remove any existing versions of Node.js before continuing.
Normally, you can do this through the package manager that installed it.

NOTE: If you're running Ubuntu 22, you will need to follow this: Ubuntu 22: Removing Existing Node.js

Check if Node.js was installed via APT: 

dpkg -l | grep nodejs

If found, remove it with this:

sudo apt remove --purge nodejs npm -y
sudo apt autoremove -y

If Node.js was installed, via NVM (Node Version Manager), and you want to remove a version that NVM is maintaining, do this:

nvm uninstall <version>

Ex; nvm uninstall 16 or nvm uninstall 18

Install Single Node.js Version

NOTE: This will install a single Node.js version.
See the later section for installing multiple Node.js versions.

Use this to install the desired version of Node.js:

sudo apt update
sudo apt-get install -y ca-certificates curl gnupg
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
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y

Verify the node version with this: sudo node -v