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
🌐
Linode
linode.com › docs › guides › install-nodejs-on-ubuntu-22-04
Installing Node.js on Ubuntu 22.04 | Linode Docs
February 24, 2023 - Install Node.js: sudo apt install -y nodejs · Once the install is complete, verify your Node.js installation: node -v · This information is important, as you may need a different version of Node.js to perform a particular task.
Discussions

What's the command to install Node on Ubuntu?
https://nodejs.org/en/download More on reddit.com
🌐 r/MeshCentral
10
0
May 12, 2025
Can't install NodeJS v18.12.0 / v18.12.1 on Ubuntu 20.04?
You should install NodeJS with tools like nvm or Volta. You will avoid Node version issues More on reddit.com
🌐 r/node
7
9
November 26, 2022
Why is it so hard to update Node on Linux? And why I still see old version of node after using "n" to update
Use nvm! It’s so slick and makes managing many versions so simple. More on reddit.com
🌐 r/node
21
20
November 12, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › installation-of-node-js-on-linux
How to Install Node.js on Linux - GeeksforGeeks
July 12, 2025 - Snap is another method for installing Node.js on Linux, especially for those who prefer installing software in a containerized form. On Ubuntu and other distributions that support Snap, you can install Node.js directly:
🌐
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
🌐
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)
Find elsewhere
🌐
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 - Running the following commands is all that’s needed for the installation. sudo apt -y install nodejs · You can as well install development tools used to build native addons: sudo apt -y install gcc g++ make ·
🌐
Node.js
nodejs.org › en › blog › release › v12.13.0
Node.js — Node.js v12.13.0 (LTS)
This release marks the transition of Node.js 12.x into Long Term Support (LTS) with the codename 'Erbium'. The 12.x release line now moves into "Active LTS" and will remain so until October 2020.
🌐
Hostinger
hostinger.com › home › how to install node.js on ubuntu automatically and manually
How to install node.js on Ubuntu automatically and manually
July 22, 2025 - In this article, we'll provide 4 easy methods to install Node.js on Ubuntu using the pre-made Hostinger VPS template, using APT and NPM + more.
🌐
Node.js
nodejs.org › en › download › archive › v25.2.1
Node.js® Download Archive
4 weeks ago - Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.
🌐
GitHub
gist.github.com › moeiscool › 4a7776bb90f12496bd797ceb85ca0ba8
Install Node.js 12 on Ubuntu 20.04 · GitHub
Install Node.js 12 on Ubuntu 20.04. GitHub Gist: instantly share code, notes, and snippets.
🌐
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
🌐
Vultr
docs.vultr.com › installing-node-js-and-express-on-ubuntu-20-04
Installing Node.js and Express on Ubuntu 20.04 | Vultr Docs
April 1, 2025 - To install Node.js, you can either install a more stable version of Node.js from the official Ubuntu 20.04 repositories, install the latest versions using Personal Package Archive (PPA) from NodeSource, or install using Node Version Manager (nvm).
🌐
Visual Studio Code
code.visualstudio.com › docs › nodejs › nodejs-tutorial
Node.js tutorial in Visual Studio Code
November 3, 2021 - Linux: There are specific Node.js packages available for the various flavors of Linux. See Installing Node.js via package manager to find the Node.js package and installation instructions tailored to your version of Linux.
Top answer
1 of 2
4

I had problems with this as well. So there are many tutorials how to install different version of nodejs but they did not work in my case. However the last with nvm did.

Method 1: Install nodejs from specific source

cd ~
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh

by changing setup_16.x to your version, you change the version

sudo bash nodesource_setup.sh

then you test sources with

# sample on Ubuntu 22.10
$ cat /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_16.x focal main
deb-src https://deb.nodesource.com/node_16.x focal main

Then you install nodejs from that source (did not work in my case)

sudo apt -y install nodejs

And check installed version

node -v

This should return

v16.19.0

but in my case (Ubuntu 22.10) I got the new version

v18.7.0

Method 2: Install Node Vesrion Manager or nvm This worked in my case:

sudo apt install curl 
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash 
source ~/.bashrc 

Now to install an older version of nodejs with nvm

you can first check available versions by

nvm list-remote

and then install specific version by (ex. version v16.19.0)

nvm install 16.19.0

and check with:

$ node -v
v16.19.0

To install latest version of node with nvm

nvm install node 

$ node -v
v18.7.0

Hope this helps someone to

2 of 2
0

Install NVM, and the install node using nvm. Here is an example.

  1. Install nvm

     ubuntu@ip-172-26-0-227:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
     % Total    % Received % Xferd  Average Speed   Time    Time     Time  
     Current
                                  Dload  Upload   Total   Spent    Left  
     Speed
     100 16555  100 16555    0     0   198k      0 --:--:-- --:--:-- --:--:--  199k
    
      => Compressing and cleaning up git repository
    
      => Appending nvm source string to /home/ubuntu/.bashrc
      => Appending bash_completion source string to /home/ubuntu/.bashrc
      => Close and reopen your terminal to start using nvm or run the following to use it now:
    
     export NVM_DIR="$HOME/.nvm"
     [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
     [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # 
     This loads nvm bash_completion
    
  2. Source bashrc so nvm can be loaded, or close and re open terminal.

    ubuntu@ip-172-26-0-227:~$ source /home/ubuntu/.bashrc

  3. Now, install node version, passing the version..etc.

    ubuntu@ip-172-26-0-227:~$ nvm install  v12.22.10
    Downloading and installing node v12.22.10...
    Downloading https://nodejs.org/dist/v12.22.10/node-v12.22.10-linux- 
    x64.tar.xz..100.0%
    Computing checksum with sha256sum
    Checksums matched!
    Now using node v12.22.10 (npm v6.14.16)
    Creating default alias: default -> v12.22.10
    
🌐
Node.js
nodejs.org › en › download
Node.js — Download Node.js®
Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.
🌐
ServerMania
servermania.com › home › how to › software installation › how to install node.js on ubuntu
How To Install Node.js on Ubuntu - ServerMania | ServerMania
July 17, 2024 - This step-by-step tutorial will show you how to install Node.js on an Ubuntu server using several different methods.
🌐
HowDev
how.dev › answers › how-to-install-nodejs-on-ubuntu
How to install Node.js on Ubuntu
After successfully adding the PPA to the system, execute the command below to install Node on Ubuntu: sudo apt-get install nodejs · To verify any installation, check the version number of the installed software.