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

Answer from eballeste on askubuntu.com
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.

🌐
NodeSource
nodesource.com › blog › Update-Node.js-versions-on-linux
How to Update Node.js Versions on Linux
January 31, 2025 - Download the latest Node.js binary: curl -fsSL https://nodejs.org/dist/latest/node-v23.8.0-linux-x64.tar.xz -o node.tar.xz ... Update your system’s PATH: echo 'export PATH=/usr/local/nodejs/bin:$PATH' >> ~/.bashrc source ~/.bashrc
Discussions

How to update node on my WSL Ubuntu?
In general, for your local setup, I would recommend to use NVM https://github.com/nvm-sh/nvm More on reddit.com
🌐 r/node
8
1
April 21, 2024
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
Fresh install...can't seem to update nodejs/ npm on ubuntu?
Install using NVM? https://nodejs.org/en/download/package-manager More on reddit.com
🌐 r/node
4
0
February 4, 2024
[deleted by user]
🌐 r/Ubuntu
24
5
April 18, 2024
🌐
eSparkBiz
esparkinfo.com › how to update node js
How To Update Node JS To Latest Version? (Complete Guide) - eSparkBiz
March 12, 2025 - To check the version installed on the system: ‘nodejs –v’ · Verify NPM version on the system: ‘npm version’ · To update the NPM manually to the latest version: ‘npm install -g npm@latest
Price   $12
Address   1001 - 1009 10th floor City Center 2, Sukan Mall Cross Road, Science City Rd, 380060, Ahmedabad
🌐
NodeSource
nodesource.com › pages › content-how-to-update-nodejs-wb.html
Full Content: How to Update Node.js Versions
NodeSource is the safest and most secure Node.js platform. Secure. Reliable. Extensible.
🌐
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.
Find elsewhere
🌐
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 - The best way to install Node.js ... management. ... # Install Node.js using NVM nvm install node # Install Node.js using NodeSource PPA sudo apt update && sudo apt install nodejs......
🌐
Medium
safaetulahasan.medium.com › how-to-install-nodejs-on-ubuntu-20-04-lts-ec10c0829429
How to install and update Nodejs on Ubuntu 20.04 LTS | by Safaetul Ahasan | Medium
September 10, 2022 - How to install and update Nodejs on Ubuntu 20.04 LTS Using Command Install Specific Nodejs version. Download tar.xz the file then install it. Update Nodejs: Uninstall NodeJs. Uninstall the previous …
🌐
Joshtronic
joshtronic.com › 2023 › 04 › 23 › how-to-install-nodejs-20-on-ubuntu-2004-lts
How to install Node.js 20 on Ubuntu 20.04 LTS - Joshtronic
April 23, 2023 - If you're distro is based on either of those, there's a good chance this will work there too. All right, so let's get started! First, I always like to make sure my system is up to date and that we have curl installed: $ sudo apt update $ sudo apt upgrade $ sudo apt install -y curl
🌐
Medium
medium.com › @redswitches › install-the-latest-node-js-version-on-ubuntu-22-04-ca7d7c83a5b0
Install the Latest Node.js Version on Ubuntu 22.04 | Medium
August 29, 2024 - To update Node.js, you can use nvm to install the latest version. For npm, you can run npm install -g npm to update it to the latest version.
🌐
OpenReplay
blog.openreplay.com › update-node-npm-guide
How to Update Node and NPM on Windows, Mac, and Linux (2024 Guide)
Update Node.js using apt: Run sudo apt-get update and then sudo apt-get install -y nodejs
🌐
Reddit
reddit.com › r/node › how to update node on my wsl ubuntu?
r/node on Reddit: How to update node on my WSL Ubuntu?
April 21, 2024 -

I have downloaded node on my win and it shows 20.11.1 while using node -v command. but when I use the same command on wsl ubuntu it shows v10.19.0. how to update it on wsl?

installed node using sudo apt install node

🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to update node.js version on linux, windows, and macos
How to Update Node.js Version on Linux, Windows, and macOS
1 day ago - However, if you use an environment without package managers, follow the steps outlined below to update Node.js using binary packages. 1. Navigate to Node's official downloads page. Choose the appropriate version, OS, and system architecture.
🌐
Flavio Copes
flaviocopes.com › ubuntu-how-to-upgrade-nodejs
Ubuntu how to upgrade Node.js
January 27, 2023 - I was running a Node service on Ubuntu and I was stuck on an old Node.js version. Here’s what I did to update to the latest available: curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt-get install -y nodejs
🌐
It's FOSS
itsfoss.com › upgrade-node-ubuntu
Properly Upgrade Node.js to a Newer Version in Ubuntu
February 28, 2024 - This will replace the sources file to point to version 21. Now, just update your system, to update the Node.js version to 21.
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › installation-of-node-js-on-linux
How to Install Node.js on Linux - GeeksforGeeks
July 12, 2025 - Once updates are installed you ... Node.js. You can install Node.js directly from the official Ubuntu repositories. sudo apt install nodejs ·...
🌐
GitHub
github.com › nvm-sh › nvm
GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
Alpine 3.13+ requires python3 to successfully build newer NodeJS versions, but you can use python2 with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script.
Starred by 90.4K users
Forked by 9.7K users
Languages   Shell 98.0% | Makefile 1.2%
🌐
VSYS
vsys.host › how-to › how-to-update-node-js-version
How to Update Node.js Version ★ VSYS Tutorials
October 4, 2024 - To update Node.js using the APT ... sudo apt update · 2. To upgrade Node.js, execute the following command: sudo apt install nodejs ·...
🌐
Reddit
reddit.com › r/node › why is it so hard to update node on linux? and why i still see old version of node after using "n" to update
r/node on Reddit: Why is it so hard to update Node on Linux? And why I still see old version of node after using "n" to update
November 12, 2022 -

Using Ubuntu 22.04, I first installed node and npm using apt commands:

sudo apt install node
sudo apt install npm

But from some reason it did not install the LTS version of node, instead it installed v12.22.9.

Then I tried to look for ways to update to the latest version, but no, not a simple way to do that:

Either use nvm, or n, or npx or from source?

So I used n as seen here: https://www.freecodecamp.org/news/how-to-update-node-and-npm-to-the-latest-version/

I ran these commands:

sudo npm install -g n
sudo n lts
sudo n prune

It did show me:

copying : node/18.12.1

installed : v18.12.1 (with npm 8.19.2)

but when I type node -v, I still get v12.22.9, so it did not uninstall the older version and did not use the newer version in the path

How can I safely undo everything and only leave my machine with the LTS version of node and npm?