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
Answer from Krapp on Stack Overflow
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
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.

🌐
Joshtronic
joshtronic.com › 2022 › 04 › 24 › how-to-install-nodejs-18-on-ubuntu-2004-lts
How to install Node.js 18 on Ubuntu 20.04 LTS - Joshtronic
The provided script will add in some new apt sources and even runs apt update to ensure we have our cache primed and ready to rock! Once the script is done running, you can install or upgrade to Node.js 18: sudo apt install -y nodejs · And once that's finished running, we can check that we ...
🌐
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.
🌐
YouTube
youtube.com › watch
Update Node js Version to 18 Ubuntu - YouTube
Ubuntu update node js version to 18, 20, 21, 22, etc on the command line or terminal, Just install node js latest version and switch node js version using co...
Published   January 24, 2024
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-node-js-on-ubuntu-18-04
How To Install Node.js on Ubuntu 18.04 | DigitalOcean
December 29, 2021 - In this guide, you’ll learn about three different methods to install Node.js on an Ubuntu 18.04 server.
🌐
D4b
d4b.dev › blog › 2024-03-03-upgrade-nodejs-to-18-on-ubuntu-20
How to upgrade Node.js to 18 on Ubuntu 20.04 LTS - d4b
$ sudo apt update $ sudo apt upgrade $ sudo apt install -y curl · Now lets add the custom repository for Node.js 18 and install it. $ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - $ sudo apt-get install -y nodejs
🌐
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 - Learn how to safely upgrade Node.js on Ubuntu using NVM, package managers, or binary distributions. Follow our step-by-step guide for a smooth version update.
Find elsewhere
🌐
Net2
net2.com › home › how to update node js on ubuntu 18.04
How to update Node JS on Ubuntu 18.04
February 28, 2023 - In this short tutorial, you will discover three ways to update NodeJs on Ubuntu 18.04 and 20.04. Using nvm Let's start with NVM, Node Version Manager. It
🌐
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
🌐
Ste Wright
stewright.me › install-nodejs-18-on-ubuntu-22-04
Tutorial - Install NodeJS 18 on Ubuntu 22.04
April 3, 2023 - ENter the following command which will add the PPA sources for NodeJS 18 on your Ubuntu 22.04 installation: curl -s https://deb.nodesource.com/setup_18.x | sudo bash · Once installation is complete, the console should output the results to ...
🌐
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 update · sudo apt install nodejs npm · However, the version provided by default Ubuntu repositories might not be the latest. For newer versions of Node.js (Recommended for most users): Using NodeSource repositories is a popular and reliable method.
🌐
Learn Ubuntu
learnubuntu.com › update-node-js
Update Node.js version in Ubuntu Command Line
October 16, 2023 - Say, you are using Node.js version 16 and you want to upgrade to version 18, just use the installer script of your desired version as specified above. The script rewrites the entry in /etc/apt/sources.list.d/nodesource.list file with the new ...
🌐
TecAdmin
tecadmin.net › how-to-install-node-js-on-ubuntu-24-04
How to Install Node.js (20, 18, 16) on Ubuntu 24.04 – TecAdmin
April 26, 2025 - Replace “20” with the version number of Node.js you want to install, like 22, 18, 16, 14, or any other version. ... This command will display the currently installed version of Node.js. You can also use the official Node.js packages from Nodesource, which are available for Debian-based systems.
🌐
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
🌐
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 # ...
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!

🌐
LinuxVox
linuxvox.com › blog › ubuntu-update-node-version
Ubuntu Update Node Version: A Comprehensive Guide — linuxvox.com
# For Node.js 18.x curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - # Update the package list sudo apt update · # Install Node.js and npm sudo apt install nodejs npm # Verify the installation node -v npm -v · Backup Your Projects: ...
🌐
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
3 days ago - This guide shows how to update Node.js version on Linux, Windows, or macOS. Follow our step-by-step tutorial and upgrade now.