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
People also ask

What is Node.js?
Node.js is a server side scripting based on Google’s V8 JavaScript engine
🌐
linuxhelp.com
linuxhelp.com › how-to-install-node-js-12-on-ubuntu-19-04
How to Install Node.js 12 on Ubuntu 19.04 | LinuxHelp Tutorials
What are the features of Node.js?
Node.js is a single-threaded but highly scalable system that utilizes JavaScript as its scripting language
🌐
linuxhelp.com
linuxhelp.com › how-to-install-node-js-12-on-ubuntu-19-04
How to Install Node.js 12 on Ubuntu 19.04 | LinuxHelp Tutorials
Where can you use Node.js?
Node.js is used to build scalable programs especially web applications which are computationally simple but are frequently accessed
🌐
linuxhelp.com
linuxhelp.com › how-to-install-node-js-12-on-ubuntu-19-04
How to Install Node.js 12 on Ubuntu 19.04 | LinuxHelp Tutorials
🌐
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.
🌐
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 # ...
🌐
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
🌐
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)
🌐
LinuxHelp
linuxhelp.com › how-to-install-node-js-12-on-ubuntu-19-04
How to Install Node.js 12 on Ubuntu 19.04 | LinuxHelp Tutorials
May 29, 2020 - Install the node packages. You can use the following command · root@linuxhelp:~# apt install nodejs Reading package lists... Done Building dependency tree Reading state information...
🌐
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:
🌐
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.
🌐
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 › 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
🌐
Hostman
hostman.com › tutorials › how to install node.js on ubuntu 22.04
Installing Node.js on Ubuntu 22.04
July 2, 2025 - In this guide, you will find three methods of installing Node.js on Ubuntu 22.04. To follow the steps from this tutorial, you will need: A computer or a cloud server running Ubuntu 22.04. A user with sudo privileges. This method is the fastest, however, it does not allow you to select a specific version. From the Ubuntu repository, you can download only one Node.js version, 12...
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Reddit
reddit.com › r/node › can't install nodejs v18.12.0 / v18.12.1 on ubuntu 20.04?
r/node on Reddit: Can't install NodeJS v18.12.0 / v18.12.1 on Ubuntu 20.04?
November 26, 2022 -

Homebridge is telling me to update NodeJS to the latest version (v18.12.1). However, my Ubuntu 20.04 system refuses to see a newer version than v18.11.0 (see log output). Any idea how to solve this, preferably without upgrading Ubuntu to a newer version?

kraken@scylla:~$ sudo hb-service update-node
ℹ Updating Node.js from v18.11.0 to v18.12.1...
ℹ Updating from NodeSource...
Hit:1 http://old-releases.ubuntu.com/ubuntu impish InRelease
Hit:2 http://old-releases.ubuntu.com/ubuntu impish-security InRelease     
Get:3 https://download.docker.com/linux/ubuntu hirsute InRelease [48,9 kB]
Hit:4 https://deb.nodesource.com/node_18.x impish InRelease
Fetched 48,9 kB in 1s (56,9 kB/s)
Reading package lists... Done

## Installing the NodeSource Node.js 18.x repo...


## Populating apt-get cache...

+ apt-get update
Hit:1 https://deb.nodesource.com/node_18.x impish InRelease
Get:2 https://download.docker.com/linux/ubuntu hirsute InRelease [48,9 kB]      
Hit:3 http://old-releases.ubuntu.com/ubuntu impish InRelease                                
Hit:4 http://old-releases.ubuntu.com/ubuntu impish-security InRelease
Fetched 48,9 kB in 1s (88,5 kB/s)
Reading package lists... Done

## Confirming "impish" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_18.x/dists/impish/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null

## Creating apt sources list file for the NodeSource Node.js 18.x repo...

+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x impish main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x impish main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
Hit:1 http://old-releases.ubuntu.com/ubuntu impish InRelease
Get:2 https://download.docker.com/linux/ubuntu hirsute InRelease [48,9 kB]                       
Hit:3 http://old-releases.ubuntu.com/ubuntu impish-security InRelease                                        
Hit:4 https://deb.nodesource.com/node_18.x impish InRelease                                                  
Fetched 48,9 kB in 0s (105 kB/s)                     
Reading package lists... Done

## Run `sudo apt-get install -y nodejs` to install Node.js 18.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.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn


Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
nodejs is already the newest version (18.11.0-deb-1nodesource1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
ℹ Restarting Homebridge Service...
✔ Homebridge Restarted