# 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](https://wiki.galaxydump.com/link/109)

<p class="callout warning">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.</p>

#### 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.

<p class="callout warning">NOTE: If you're running Ubuntu 22, you will need to follow this: [Ubuntu 22: Removing Existing Node.js](https://wiki.galaxydump.com/link/115)</p>

Check if Node.js was installed via APT:

```bash
dpkg -l | grep nodejs
```

If found, remove it with this:

```bash
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:

```bash
nvm uninstall <version>
```

Ex; `nvm uninstall 16` or `nvm uninstall 18`

#### Install Single Node.js Version<button aria-hidden="true" class="cc-1r0b9w7" data-testid="anchor-button" type="button"><svg height="24" role="presentation" viewbox="0 0 24 24" width="24"></svg></button>

<p class="callout info">NOTE: This will install a single Node.js version.  
See the later section for installing multiple Node.js versions.</p>

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

```bash
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: <span class="prismjs cc-zn1qqt" data-code-lang="" data-ds--code--code-block="" data-testid="renderer-code-block">`<span class="" data-ds--code--row="" data-testid="renderer-code-block-line-1"><span class="">sudo node -v</span></span>`</span>