Categories: TutorialsUbuntu

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

Sponsored

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

curl -o https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | 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.

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 :

Sponsored

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.

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:

wget https://nodejs.org/dist/v14.15.3/node-v14.15.3-linux-x64.tar.xz

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

The post How to update Node JS on Ubuntu 18.04 appeared first on net2.

Ubuntu Server Admin

Recent Posts

Join Canonical in Brazil at Dell Technologies Forum São Paulo

Canonical is excited to be a part of the Dell Technologies Forum in São Paulo…

4 days ago

6 facts for CentOS users who are holding on

In 2020, it was announced that CentOS 7 would reach end of life (EoL) by…

4 days ago

What is Ubuntu used for?

The launch of Ubuntu in 2004 was a step-change for everyday users and developers everywhere.…

5 days ago

Ubuntu Weekly Newsletter Issue 862

Welcome to the Ubuntu Weekly Newsletter, Issue 862 for the week of October 13 –…

6 days ago

New Ubuntu Community Council 2024

Merlijn writes: I’m happy to announce the new 2024 Ubuntu Community Council! Heather Ellsworth (~hellsworth1)…

7 days ago