How to update Node JS on Ubuntu 18.04

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 is by far the best method to update NodeJS on Linux machines.

You will need a C ++ compiler, the package build-essential and the library libssl-dev. Run an update first, then we’ll install the packages.

sudo apt-get update

To install the packages, run the command :

sudo apt-get install build-essential checkinstall libssl-dev

How to install NVM: To install or update NVM, you can get the installation script using cURL:

curl -o | bash

To check if the installation was successful, invoke the command :

nvm -v

The command will return the version of nvm if all goes well. Your Node JS update will become easy.

Read: How to install Node.js on Linux/Ubuntu

You can check which versions are currently installed with the command :

nvm ls

To see the latest npm version for installation, run the command :

nvm ls-remote

Download, install and compile the latest versions of Node JS using

nvm install #. #. #                        [update nodejs ubuntu]

Replace the #s with the required Node JS version.

Read: Best Nodejs Frameworks for Web Apps in 2023

Using a package manager

If NVM didn’t work for you, a package manager is now your best alternative.

The Node Package Manager, or NPM, helps you discover, share, and use code, along with dependencies. Node JS comes with npm pre-installed, but it is updated more often than Node.

Run the command:

npm -v

To see what your current version is.

Now to install the latest version of npm, execute the command :

npm install npm@latest -g [install npm ubuntu]

Next invoke :

npm -v

Again to make sure that the update has been done correctly.

Now to update Node JS, you will need an npm module called “n”.

Run the lines of code below on your terminal to clear the npm cache, install the “n” module and install the latest stable version of Node JS.

sudo npm cache clean -f

sudo npm install -g n

sudo n stable

To install the latest version, run the command :

sudo n latest

Or otherwise, you could also execute:

sudo n #. #. #

As it was the case with the first method, replace the #s with the required Node JS version.

Read: How to Uninstall NodeJS from Ubuntu 22.04

Using binary packages

If you are desperate and the other options didn’t work out, you can visit the official downloads page to get a 32-bit or 64-bit binary package.

You can install the package via the browser itself, but if you prefer to use the terminal, keep in mind that the specific version of the node may change while updates are released.

On your terminal, run the command:


To unzip the file, you will need the xz-utils package, to install it, run :

sudo apt-get install xz-utils

Now run the command below to extract and install the binary package in /usr/local:

tar -C /usr/local –strip-components 1 -xJf node-v14.15.3-linux-x64.tar.xz

If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.


amin nahdy

Amin Nahdy, an aspiring software engineer and a computer geek by nature as well as an avid Ubuntu and open source user. He is interested in information technology especially Linux based ecosystem as well as Windows and MacOS. He loves to share and disseminate knowledge to others in a transparent and responsible way.

Leave a Reply