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.

Discussions

update auf node.js 18.XX
Und dein 5 Jahre altes Ubuntu ist tot. Da wird kein aktuelles nodejs drauf laufen. Aktualisieren. ... @thomas-braun o.k. danke Dir für die Info...das ist der fixer O.K. Nächste Frage wäre wie ich das bestehende Linux system auf ein aktuelles Update...da ich kein LinuxUser bin sag ichs ehrlich ... More on forum.iobroker.net
🌐 forum.iobroker.net
October 1, 2023
I need to install Python and Node.js in a Ubuntu 18.04 container
You’ll need to make one! Start with ubuntu:18.04 as your base image, then install your desired version of python and node via apt & apt-get. Depending on what your end goal is, you may eventually find a need to break these up into two different services. More on reddit.com
🌐 r/docker
4
0
January 15, 2020
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
Not able to install nodejs from deb.nodesource.com
The cause of the problem is that you're using Ubuntu 20.10 ("groovy"). Support for that version ended almost two years ago. You should switch to a version that is still supported. More on reddit.com
🌐 r/Ubuntu
5
1
February 3, 2023
🌐
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
April 24, 2022 - 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.
🌐
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.
🌐
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.
🌐
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
Find elsewhere
🌐
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 ...
🌐
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.
🌐
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.
🌐
Node.js
nodejs.org › en › download › package-manager › all
Node.js — Installing Node.js via package manager
October 15, 2025 - dnf module install nodejs:18/common · ShellCopy to clipboard · These resources provide packages compatible with CentOS, Fedora, and RHEL. Node.js snaps maintained and supported at https://github.com/nodejs/snap · Node.js binary distributions ...
🌐
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.
🌐
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
🌐
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 - Since we will use Ubuntu 22.04, we should be able to install a more recent version of Node.js. Here are the steps: Update your Ubuntu’s repository to ensure you get the latest available version:
🌐
Linuxbeast
linuxbeast.com › home › how to switch node.js version in wsl ubuntu
How to Switch Node.js Version in WSL Ubuntu | Linuxbeast
June 9, 2024 - This guide will help you set up and make a specific Node.js version (e.g., v20.12.2 latest LTS) the default in your WSL Ubuntu for seamless development.
🌐
YouTube
youtube.com › tuts make
Install Node js 18 on Ubuntu 22.04 - YouTube
In this video, we are going to show you how to install node js 18, 16, 17, etc version on ubuntu 22.04.Here are the commands to completely install node js 18...
Published   January 7, 2024
Views   640
🌐
Linuxbeast
linuxbeast.com › home › how to switch node.js version in wsl ubuntu
How to Switch Your Node.js Version in WSL Ubuntu to 18.17
June 9, 2024 - This guide will help you set up and make a specific Node.js version (e.g., v20.12.2 latest LTS) the default in your WSL Ubuntu for seamless development.
🌐
Node.js
nodejs.org › en › download › package-manager
Node.js — Download Node.js®
August 9, 2023 - # 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 # ...
🌐
iobroker
forum.iobroker.net › home › deutsch › iobroker allgemein › update auf node.js 18.xx
update auf node.js 18.XX
October 1, 2023 - curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt install -y nodejs ... Der Ubuntu-Weg Ubuntu hat seine eigene automatische Art des Upgrades zwischen den Versionen entwickelt.
🌐
TechViewLeo
techviewleo.com › home › linux guides
Installing Node.js 18 LTS on Ubuntu 22.04|20.04|18.04 - TechViewLeo
October 6, 2023 - Once the repository has been added, install Node.js 18 LTS on Ubuntu using the command: ... Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: libfwupdplugin1 Use 'sudo apt autoremove' to remove it. The following NEW packages will be installed: nodejs ...