There is a npm package called "n" that handles node version management. Additionally, it supports convenient version naming, such as "current, "lts" or "18.12.1".

So, in your shell, type these commands:

sudo npm install -g n
sudo n lts
Answer from Eren 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 - $ sudo apt-get update -y $ 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 $ NODE_MAJOR=20 $ echo "deb [signed-by=/etc/apt/ke...
🌐
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. Regular updates ensure you have the latest features and security patches.
🌐
Joshtronic
joshtronic.com › 2024 › 05 › 26 › ubuntu-nodejs-22-install
How to install Node.js 22 on Ubuntu - Joshtronic
% echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list · With the source repository added, we're ready to install the package. First, we need to run another update to sync the package list, then we can proceed with installing Node.js 22:
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.

🌐
Vultr
docs.vultr.com › how-to-upgrade-a-node-js-version-on-ubuntu
How to Upgrade Node.js Version on Ubuntu Complete Guide | Vultr Docs
May 22, 2025 - This method upgrades Node.js by adding the official NodeSource repository and is ideal for system-managed environments or automated server setups. Download and run the NodeSource setup script. Replace <version> with the major version number ...
Top answer
1 of 4
90

I recommend using Node Version Manager:

NB: Node Version Manager (nvm) allows you to install multiple node versions and choose between them depending on which software you want to support; that is, manage multiple node versions.

Installing Node Version Manager

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

Once you have Node Version Manager installed

  1. Confirm the available remote versions by running nvm ls-remote
  2. Run in your terminal nvm install <version> for example, nvm install 18 to install version 18 of Node
  3. List installed versions with nvm list
  4. Run nvm use 18 to start using version 18 of Node
  5. Note: you can be more explicit, for example: nvm install 14.17.0
2 of 4
29

Install nodejs v20 on Debian and Ubuntu based distributions

step 1 : Download and import the Nodesource GPG key

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

step 2 : Create deb repository

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

optional: here we are installing nodejs v20 but if you want to install v18 change NODE_MAJOR=18 in above command. Similarly if you want to install nodejs v16 then change NODE_MAJOR=16.

step 3 : Run Update and Install

sudo apt-get update
sudo apt-get install nodejs -y

congratulations you just installed nodejs

To uninstall nodejs

sudo apt-get purge nodejs &&\
rm -r /etc/apt/sources.list.d/nodesource.list &&\
rm -r /etc/apt/keyrings/nodesource.gpg
Find elsewhere
🌐
It's FOSS
itsfoss.com › upgrade-node-ubuntu
Properly Upgrade Node.js to a Newer Version in Ubuntu
February 28, 2024 - At the time of writing this, for Ubuntu 22.04 and Debian 12 Bookworm, Node.js version 18, 20, and 21 are supported. Node provides a script for each active major version. You just have to replace YY with the version you want in the following command: curl -fsSL https://deb.nodesource.com/setup_YY.x | sudo -E bash - Let’s say you have installed version 18 of Node.js using the NodeSource repository, and you want to update it to version 21.
🌐
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
Top answer
1 of 16
1868

Ubuntu Linux/Mac

The module n makes version-management easy:

sudo npm install n -g

For the latest stable version:

n stable

For the latest version:

n latest

Debian 10

Upgrade older versions of node and npm on Debian 10 as follows:

sudo su -c 'curl -sL https://deb.nodesource.com/setup_18.x | bash -'
sudo apt-get install nodejs -y
sudo apt update
sudo apt upgrade
sudo npm install -g [email protected]
node --version
npm --version

Note: Replace setup_18 with the latest long-term support release.

Windows

Just reinstall node from the .msi in Windows from the node website.

2 of 16
839

All Platforms (Mac, Linux & Windows) 2024

If you just need to upgrade your old version of Node.js to the latest one and don't need multiple versions, simply over-write your existing executable with the new one.

Download the Latest Node.js from nodejs.org/en/download

This Just Works! TM on all platforms and is the easiest/fastest method.
When you run node -v in your terminal you will see the the latest version.

Mac

If you originally installed Node.js using brew then run:

brew upgrade node

Managing Multiple Versions of Node.js:

If you need to run multiple versions of Node.js on your machine e.g. if you have an older project that targets a specific version on AWS Lambda, then NVM (Node Version Manger) is your friend!

Step 1 - Get NVM

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

If you're curious about the installation command read the source code
... its been reviewed by several node.js security experts

Step 2 - Install the Specific Version of Node.js you need

Once you've got NVM you can install a specific version of Node.js using the nvm command:

nvm install v22.16.0

Note: you may need to close & re-open your terminal window for nvm command to be available.

You should expect to see something like this in your terminal:

Now using node v22.16.0

You now have the latest Node.js on your machine.
And if you need to temporarily switch to a different/previous version, you can do it with a simple nvm command.

Note: avoid using sudo with Node/NPM as it violates the security principal of least privilege

NVM is considered "better" than N for managing multiple Node.js versions because the verbose commands mean it is much easier to keep track of what you are doing in your Terminal/SSH Log. It is used by the team at NPM the creators/custodians of the Node.js World!

🌐
BlueVPS
bluevps.com › blog › how to install node.js on ubuntu 22.04: step-by-step guide
How to Install Node.js on Ubuntu 22.04: Step-by-Step Guide - Blog - BlueVPS
Once you update all repositories on your system, install Node.js on the Ubuntu 22.04 system using the following command: After executing the command above, you need to confirm the user confirmation prompts, and then it will install Node.js and npm (Node Package Manager) on your system. Once Node.js is installed on the Ubuntu system, you can verify its installation using the following command: $ nodejs --version ·
🌐
OVHcloud
ovhcloud.com › tutorials › how to install node.js on ubuntu 22.04
How to install Node.js on Ubuntu 22.04 ? | OVHcloud Worldwide
To update n later, run `n-update`. To uninstall, run `n-uninstall`. IMPORTANT: OPEN A NEW TERMINAL TAB/WINDOW or run `. /home/ubuntu/.bashrc` before using n and Node.js. === ... $ n current installing : node-v18.1.0 mkdir : /home/ubuntu/n/n/versions/node/18.1.0 fetch : https://nodejs.org/d...
🌐
Hostman
hostman.com › tutorials › how to install node.js on ubuntu 22.04
Installing Node.js on Ubuntu 22.04
July 2, 2025 - To install the latest version of Node.js for Ubuntu, consider the methods 2 and 3. If installing the 12.22.9 Node.js version works for you, follow these steps. Update the package list on your system: sudo apt update · Install Node.js: sudo ...
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
SW Hosting
swhosting.com › en › blog › how-to-install-nodejs-on-ubuntu-2204
How to install NodeJS on Ubuntu 22.04 - SW Hosting's Blog
August 14, 2024 - In this post, I'll walk you through the steps required to install Node.js on a machine running Ubuntu 22.04. Before starting with the installation, it is important to make sure that your system is up to date. Open a terminal and run the following commands: ... Node Package Management, or NPM, is the default package manager for Node.js and is essential for managing dependencies in Node.js projects. It allows developers to install, update, and manage the third-party libraries and modules their projects need.
🌐
Medium
medium.com › @nsidana123 › before-the-birth-of-of-node-js-15ee9262110c
How To Install Node.js 20 LTS on Ubuntu 22.04|20.04|18.04 | by Navdeep Sidana | Medium
December 7, 2023 - This guide has demonstrated how you can start the installation of Node.js 20 LTS on Ubuntu Linux system. As seen in this article, the process is straightforward and doesn’t required any special Linux skills. By following and customizing on the steps provided, you should be able to develop more complex applications by adding extra functionality and features. We hope this article was of great help. Follow us on our social media platforms for more juicy updates. Nodejs ·
🌐
Medium
medium.com › @micodin0plant › installing-up-nodejs-latest-and-npm-latest-on-ubuntu-22-04-5523d3dbb8e7
Installing up NodeJs (latest) and Npm (latest) on Ubuntu 22.04 | by Michael | Medium
April 29, 2024 - At the time of this this installs v10 of NodeJS and v10.5.1 of Npm, where the latest node is v20! Thats 10 version behind… · sudo apt-get update sudo apt install node sudo apt install npm
🌐
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
Fortunately though, these instructions can be easily applied to newer versions of Ubuntu, like 22.04 LTS and the recently released Ubuntu 23.04, as well as many modern versions of Debian. 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