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
🌐
Node.js
nodejs.org › en › download
Node.js — Download Node.js®
Get Node.js® v24.12.0 (LTS) for Unknown · using · with npm · InfoWant new features sooner? Get the latest Node.js version instead and try the latest improvements! BashCopy to clipboard and their installation scripts are not maintained by the Node.js project.
🌐
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.
🌐
npm
docs.npmjs.com › downloading-and-installing-node-js-and-npm
Downloading and installing Node.js and npm | npm Docs
If you are unable to use a Node version manager, you can use a Node installer to install both Node.js and npm on your system. ... If you use Linux, we recommend that you use a NodeSource installer.
🌐
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
Find elsewhere
🌐
Medium
authmane512.medium.com › how-to-install-node-js-on-debian-9-without-complicated-script-of-the-website-49b51c006b69
How to install Node.js 10 or 12 on Linux Ubuntu 18.04 / Debian 9 (Stretch) without weird script of the website | by Authmane Terki | Medium
December 15, 2019 - # Using Ubuntu curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -sL https://deb.nodesource.com/setup_12.x | bash - apt-get install -y nodejs
🌐
Node.js
nodejs.org › en › blog › release › v12.13.0
Node.js — Node.js v12.13.0 (LTS)
Windows 32-bit Installer: https://nodejs.org/dist/v12.13.0/node-v12.13.0-x86.msi Windows 64-bit Installer: https://nodejs.org/dist/v12.13.0/node-v12.13.0-x64.msi Windows 32-bit Binary: https://nodejs.org/dist/v12.13.0/win-x86/node.exe Windows 64-bit Binary: https://nodejs.org/dist/v12.13.0/win-x64/node.exe macOS 64-bit Installer: https://nodejs.org/dist/v12.13.0/node-v12.13.0.pkg macOS 64-bit Binary: https://nodejs.org/dist/v12.13.0/node-v12.13.0-darwin-x64.tar.gz Linux 64-bit Binary: https://nodejs.org/dist/v12.13.0/node-v12.13.0-linux-x64.tar.xz Linux PPC LE 64-bit Binary: https://nodejs.org
🌐
Vultr
docs.vultr.com › how-to-install-node-js-and-npm-on-debian-12
How to Install Node.js and NPM on Debian 12 Complete Guide | Vultr Docs
April 1, 2025 - Learn how to install Node.js and NPM on Debian 12 with step-by-step instructions. Includes multiple installation methods and troubleshooting tips.
🌐
ComputingForGeeks
computingforgeeks.com › home › dev › install node.js 10,12 lts on ubuntu 22.04|20.04|18.04|16.04
Install Node.js 10,12 LTS on Ubuntu 22.04|20.04|18.04|16.04 | ComputingForGeeks
February 4, 2023 - After adding the repository, install Node.js 12|10 LTS on Ubuntu 18.04 /16.04 / Debian 10/9 using the apt package manager.
🌐
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 - In this guide, we will show you four different ways of getting Node.js installed on an Ubuntu server: using apt to install the nodejs package from Ubuntu’s d…
🌐
OSTechNix
ostechnix.com › home › programming › nodejs › how to install nodejs on linux
How To Install NodeJS On Linux - OSTechNix
March 4, 2025 - In this tutorial, we will see how to install Nodejs on Linux operating systems such as Arch Linux, Debian, Ubuntu, RHEL, CentOS, Fedora etc.
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › installation-of-node-js-on-linux
How to Install Node.js on Linux - GeeksforGeeks
July 12, 2025 - Installing Node.js on Linux is a relatively simple process, but it can vary depending on your distribution and preferred installation method. Using package managers like apt or yum is the easiest method for most users, while NVM provides greater flexibility for managing multiple Node.js versions.
🌐
Its Linux FOSS
itslinuxfoss.com › home › debian › how to install node.js and npm on debian 12 linux
How to Install Node.js and npm on Debian 12 Linux – Its Linux FOSS
July 18, 2023 - To install the Node.js and NPM on Debian 12, run the “sudo apt install nodejs npm -y” command in the terminal. Other methods of installing them on Debian 12 are by using the NVM or node source repository.
🌐
Reintech
reintech.io › blog › installing-nodejs-npm-debian-12
Installing Node.js and NPM on Debian 12 | Reintech media
May 28, 2025 - This article guides software developers through the process of installing Node.js and NPM on Debian 12, including updating the system, adding the NodeSource repository, and verifying the installation.
🌐
Medium
medium.com › @brugbarros › instalando-o-node-js-12-no-ubuntu-1612fa69b768
Instalando o Node.js 12.x no Ubuntu | by Bruno Barros | Medium
July 19, 2019 - curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - Após concluir o download, digite o comando para instalar: sudo apt-get install nodejs · E pronto :) Agora basta digitar node -v ou npm -v e verificar que o Node.js já está instalado ...
🌐
CrownCloud Wiki
wiki.crowncloud.net
How To Install Node JS On Debian 12
Node.js is an open source server environment. Node.js allows you to run JavaScript on the server. Login to the Debian 12 server. Install stable nodejs from the Debian repository by running the following command.
🌐
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