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-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
🌐
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 ·
🌐
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 ·
🌐
UbuntuUpdates
ubuntuupdates.org › ppa › nodejs_12.x
UbuntuUpdates - PPA: Nodejs 12.x
$ sudo sh -c "echo deb https://deb.nodesource.com/node_12.x bionic main \ > /etc/apt/sources.list.d/nodesource.list" $ sudo apt-get update $ sudo apt-get install nodejs More info at: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
🌐
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 · Because the repository ...
🌐
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 - $ sudo apt-get update -y $ sudo ...rce.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list $ sudo apt-get update $ sudo apt-get install -y nodejs $ node -v v20.6.1 $ npm -v 9.8.1 ... This guide provides detailed instructions for installing ...
Find elsewhere
🌐
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.
🌐
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. sudo apt update sudo apt -y install gcc g++ make sudo apt -y install nodejs
Top answer
1 of 16
1896

Use n module from npm in order to upgrade node

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

To upgrade to latest version (and not current stable) version, you can use

sudo n latest
  • Fix PATH:

      sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node
    
  • To undo:

      sudo n rm 6.0.0     # replace number with version of Node that was installed
      sudo npm uninstall -g n
    

You may need to restart your terminal to see the updated node version.

Found in David Walsh blog

2 of 16
666

NodeSource provides binary distributions of Node.js; complete installation instructions can be found here. The instructions have been copied below for your reference. Instructions are the same for updating to the latest version.

Run once:

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

Run whenever you want to change the major version of Node.js:

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

Prior to August 2023: Previously versions of this answer involved the use of a series of setup_XX.x scripts that you'd run to install/update Node.js:

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

But as @eis pointed out, these scripts are no longer supported. To see the previous answers, please look at the edit history for this answer.

🌐
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.
🌐
TecAdmin
tecadmin.net › install-latest-nodejs-npm-on-ubuntu
How to Install Latest Node.js on Ubuntu – TecAdmin
April 26, 2025 - Installing latest node.js ubuntu. How do I Install stable node.js, npm on Ubuntu. Installing Node.js with apt-get package manager on Ubuntu
🌐
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 # ...
🌐
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
🌐
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.
🌐
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.
🌐
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)
🌐
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: