First remove nodejs using,

sudo apt-get purge --auto-remove nodejs

Then after, if curl is not installed then run the below command

sudo apt-get install curl

Then after run the below 2 commands,

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

sudo apt-get install -y nodejs

Answer from Avinash Antala on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-node-js-on-ubuntu-22-04
How to Install Node.js on Ubuntu (Step-by-Step Guide) | DigitalOcean
May 28, 2025 - This guide provides detailed instructions for installing Node.js on an Ubuntu 22.04 server using three different methods. It starts with the basic method of using apt to install Node.js from the default repositories, suitable for most users who need a stable version.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-node-js-on-ubuntu-20-04
How to Install Node.js on Ubuntu | DigitalOcean
May 2, 2025 - Learn how to install Node.js on Ubuntu using apt, NodeSource, and NVM. Choose the best method for your needs with this beginner-friendly guide
🌐
ComputingForGeeks
computingforgeeks.com › home › how to › install node.js 12 on ubuntu / debian / linux mint
Install Node.js 12 on Ubuntu / Debian / Linux Mint | ComputingForGeeks
August 18, 2023 - Running the following commands is all that’s needed for the installation. sudo apt -y install nodejs npm · You can as well install development tools used to build native addons: sudo apt -y install gcc g++ make · Confirm Node.js 12 installation ...
🌐
Cloudlaya
cloudlaya.com › blog › install-node-js-12-on-ubuntu-debian-linux
Install Node.js 12 on Ubuntu / Debian / Linux - Cloudlaya | Blog
February 23, 2022 - Learn how to Install Node.js 12 on Ubuntu / Debian / Linux and setup your own Virtual private server by yourself.
🌐
Liquid Web
liquidweb.com › home › how to install node.js on ubuntu 22.04 via nvm
How to Install Node.js on Ubuntu 22.04 via NVM | Liquid Web
February 19, 2025 - Similarly, install an older LTS release run the nvm install –lts=erbium command: ... nvm ls -> v12.22.12 v14.21.2 (LTS: Fermium) v16.19.0 (LTS: Gallium) v18.13.0 system default -> node (-> v18.13.0) (default)
🌐
CodeGenes
codegenes.net › blog › how-can-i-install-node-js-version-18-on-ubuntu-22-04
How to Install Node.js 18 on Ubuntu 22.04: Fix 'Old Version (v12.22.9) Installed' Issue — codegenes.net
If you’ve tried installing Node.js on Ubuntu 22.04 using sudo apt install nodejs and encountered the "old version (v12.22.9)" issue, this guide will walk you through uninstalling the outdated version and installing Node.js 18 (a long-term ...
Find elsewhere
🌐
Relia Software
reliasoftware.com › blog › install-nodejs-on-ubuntu-22-04
How to Install Node.js on Ubuntu 22.04? | Relia Software
February 27, 2024 - 3 methods for installing Node.js on Ubuntu 22.04: with Ubuntu Package Manager; with NVM (Node Version Manager); and from Official Node.js Binary Distributions.
Price   $$$$$
Address   629 Nguyen Kiem, Ward 9, Phu Nhuan District, 700000, Ho Chi Minh
🌐
Node.js
nodejs.org › en › download › package-manager
Node.js — Download Node.js®
# download and install Node.js (you may need to restart the terminal) nvm install 22 # verifies the right Node.js version is in the environment node -v # should print "v22.12.0" # verifies the right npm version is in the environment npm -v # ...
🌐
VSYS
vsys.host › how-to › how-to-installing-node-js-on-ubuntu-22-04
How to Install Node.js on Ubuntu 22.04 ★ VSYS Tutorials
June 20, 2024 - It is technically obsolete, but it should be supported until Ubuntu 24.04. You can obtain this version by using the apt package manager. First, refresh your local package index by typing: ... When prompted to confirm installation, press Y.
🌐
Linuxize
linuxize.com › post › how-to-install-node-js-on-ubuntu-20-04
How to Install Node.js and npm on Ubuntu 20.04 | Linuxize
December 24, 2023 - In this tutorial, we will guide you through three different methods of installing Node.js and npm on Ubuntu 20.04:
🌐
Node.js
nodejs.org › en › blog › release › v12.22.1
Node.js — Node.js v12.22.1 (LTS)
Windows 32-bit Installer: https://nodejs.org/dist/v12.22.1/node-v12.22.1-x86.msi Windows 64-bit Installer: https://nodejs.org/dist/v12.22.1/node-v12.22.1-x64.msi Windows 32-bit Binary: https://nodejs.org/dist/v12.22.1/win-x86/node.exe Windows 64-bit Binary: https://nodejs.org/dist/v12.22.1/win-x64/node.exe macOS 64-bit Installer: https://nodejs.org/dist/v12.22.1/node-v12.22.1.pkg macOS 64-bit Binary: https://nodejs.org/dist/v12.22.1/node-v12.22.1-darwin-x64.tar.gz Linux 64-bit Binary: https://nodejs.org/dist/v12.22.1/node-v12.22.1-linux-x64.tar.xz Linux PPC LE 64-bit Binary: https://nodejs.org
🌐
Linuxize
linuxize.com › post › how-to-install-node-js-on-ubuntu-22-04
How to Install Node.js and npm on Ubuntu 22.04 | Linuxize
December 24, 2023 - To install the latest available version of Node.js, run: ... -> v14.19.3 v16.15.0 v18.2.0 default -> node (-> v18.2.0) iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v18.2.0) (default) stable -> 18.2 (-> v18.2.0) (default) lts/* -> lts/gallium (-> v16.15.0) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.17.0 (-> N/A) lts/dubnium -> v10.24.1 (-> N/A) lts/erbium -> v12.22.12 (-> N/A) lts/fermium -> v14.19.3 lts/gallium -> v16.15.0
Top answer
1 of 4
90

I recommend using Node Version Manager:

NB: Node Version Manager (nvm) allows you to install multiple node versions and choose between them depending on which software you want to support; that is, manage multiple node versions.

Installing Node Version Manager

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

Once you have Node Version Manager installed

  1. Confirm the available remote versions by running nvm ls-remote
  2. Run in your terminal nvm install <version> for example, nvm install 18 to install version 18 of Node
  3. List installed versions with nvm list
  4. Run nvm use 18 to start using version 18 of Node
  5. Note: you can be more explicit, for example: nvm install 14.17.0
2 of 4
29

Install nodejs v20 on Debian and Ubuntu based distributions

step 1 : Download and import the Nodesource GPG key

sudo apt-get 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

step 2 : Create deb repository

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

optional: here we are installing nodejs v20 but if you want to install v18 change NODE_MAJOR=18 in above command. Similarly if you want to install nodejs v16 then change NODE_MAJOR=16.

step 3 : Run Update and Install

sudo apt-get update
sudo apt-get install nodejs -y

congratulations you just installed nodejs

To uninstall nodejs

sudo apt-get purge nodejs &&\
rm -r /etc/apt/sources.list.d/nodesource.list &&\
rm -r /etc/apt/keyrings/nodesource.gpg
🌐
Pi My Life Up
pimylifeup.com › home › how to install node.js on ubuntu
How to Install Node.js on Ubuntu - Pi My Life Up
September 10, 2024 - In this tutorial, we will be walking you through the steps to install Node.js on Ubuntu.
🌐
Peterbe.com
peterbe.com › plog › node-12-on-ubuntu-19.10
How to install Node 12 on Ubuntu (Eoan Ermine) 19.10 - Peterbe.com
Done ## Run `sudo apt-get install -y nodejs` to install Node.js 12.x and npm ## You may also need development tools to build native addons: sudo apt-get install gcc g++ make ## To install the Yarn package manager, run: curl -sL https://dl.y...