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.

🌐
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 - This will set the default version to v22.16.0. Now whenever you open a new shell, this will be the default version. Although Ubuntu repositories and NodeSource offer simpler Node.js installation methods, building from source can be helpful in certain situations.
🌐
Joshtronic
joshtronic.com › 2021 › 05 › 09 › how-to-install-nodejs-16-on-ubuntu-2004-lts
How to install Node.js 16 on Ubuntu 20.04 LTS - Joshtronic
With things all up to date, let's make sure we have curl installed, as we'll be using that to download the installation script from NodeSource (which provides binary packages for Ubuntu, Debian and a bunch of their derivatives): ... Obviously if you know you already have curl installed, you don't need to run this. Once we have curl in the mix, we can download and run the setup script: curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - That script will run, gets thing added to your apt sources, and will even run another apt update to make sure you're ready to go.
🌐
It's FOSS
itsfoss.com › upgrade-node-ubuntu
Properly Upgrade Node.js to a Newer Version in Ubuntu
February 28, 2024 - You should visit the NodeSource Repository and check for the supported versions for your current distribution. Check Supported Versions of Node.js for Debian and Ubuntu-based Distributions
🌐
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 - 16.x with your preferred version string (if different): ... Refer to the NodeSource documentation for more information on the available versions. Inspect the contents of the downloaded script with nano or your preferred text editor: ... When you are satisfied that the script is safe to run, exit your editor. Then run the script with sudo: ... The PPA will be added to your configuration and your local package cache will be updated automatically.
🌐
Morioh
morioh.com › p › 503e1dd53bcc
How to Install and Upgrade Node.js v12.x, v13.x on Ubuntu 18.04 LTS
This article will guide you to install Node.js 12.x, 13.x, 11.x 10.x latest version on Ubuntu 19.04, 18.04, 16.04 LTS and Debian
🌐
Learn Ubuntu
learnubuntu.com › update-node-js
Update Node.js version in Ubuntu Command Line
October 16, 2023 - ... This will work even if you have already installed Node from the Node.js repository. 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.
Find elsewhere
🌐
ComputingForGeeks
computingforgeeks.com › home › debian › how to install node.js 16 on ubuntu 22.04|20.04|18.04
How To Install Node.js 16 on Ubuntu 22.04|20.04|18.04 | ComputingForGeeks
April 18, 2022 - Another example on installation of version 16.14.1: ... nvm install v16.14.1 Downloading and installing node v16.14.1... Downloading https://nodejs.org/dist/v16.14.1/node-v16.14.1-linux-x64.tar.xz...
🌐
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
🌐
Linode
linode.com › docs › guides › install-nodejs-on-ubuntu-22-04
Installing Node.js on Ubuntu 22.04 | Linode Docs
February 24, 2023 - A task may require a specific version of Node.js. The example steps below show how to install the most current Node.js version 16.x setup.
🌐
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. Focus Mode · Text Size · 16px · AA · Contents · Prerequisites · Verify the Installed Node.js Version ·
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 6
61

To update nodejs to 14.x run the following commands:

sudo apt update
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt install -y nodejs
node -v

After running the final command you should see:

v14.15.0
2 of 6
18

Update for 2024

Since this question was posted, version 20 became the newest LTS version. So Ahmed Boutaraa's answer was correct for the version 14 part of the question, but people stumbling on this question may be seeking the most recent LTS. If you follow those instructions, you will be stuck in version 14.

Luckily, NodeSource also provides an installation script that installs the current LTS rather than a specific version. That should make this answer a bit more future-proof. You can also get the same info straight from the source.

As an aside, there is a script called nvm that is great for managing your node version. It makes it easy to install multiple versions, like if you work with multiple projects with different version requirements or if you want to experiment with the latest version and easily switch back to LTS for regular work. You can find installation instructions on their repository.

How to install the latest LTS version

This set of instructions will install whatever version is the latest LTS version. When a new version is released, you may have to run these instructions again to pull the new install script for the new version.

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

# OR as root
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs

How to install the latest non-LTS version

This set of instructions will install whatever version is the latest non-LTS version. When a new version is released, you may have to run these instructions again to pull the new install script for the new version.

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

# OR as root
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs

How to lock into v21 (latest, for now)

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash -
sudo apt-get install -y nodejs

# OR as root
curl -fsSL https://deb.nodesource.com/setup_21.x | bash -
apt-get install -y nodejs

How to lock into v20 (current LST)

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

# OR as root
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
🌐
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.
🌐
Atetux
atetux.com › home › how to install nodejs 16 ubuntu 20.04 / debian 10
How To Install NodeJS 16 Ubuntu 20.04 / Debian 10 - Atetux
May 19, 2021 - Home » How To Install NodeJS 16 Ubuntu 20.04 / Debian 10 · Posted inHowto · by JackMay 19, 2021 · Node.js is a JavaScript run time which-build on top of the V8 engine develops by Google. Designed to build scalable network applications. HTTP is a first-class citizen in Node.js, designed with streaming and low latency in mind. This makes Node.js well suited for the foundation of a web library or framework. As usual, update the system to the latest version.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-node-js-on-ubuntu-16-04
How To Install Node.js on Ubuntu 16.04 | DigitalOcean
September 29, 2021 - You should not use this version, and should refer to one of the other sections in this tutorial to install a more recent version of Node. To get this version, you can use the apt-get package manager. Refresh your local package index first by typing: sudo apt-get update · Then install Node.js: ...
🌐
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 …