Update Node.js Version in Ubuntu Linux

In this article will see “How to Update Node.js version to latest version in Ubuntu Linux Systems”, It is an Open Source and cross-platform Application.

This means that it can be run on various platforms like Linux, Windows, Mac, and many other Operating Systems like this.

Because it’s Highly Scale-able and can handle more requests than any other programming language.

The biggest giant Industries like Walmart, PayPal, Netflix, etc. using Node JS.

Then in 2010, they got their Node Package manager (NPM), which is one of the largest package registries in today’s world.

If you want to learn more about Node.js then follow the link.

So, we are going to update the Node.js to latest version in Ubuntu linux by two methods or ways.

  1. Update Node.js Version using NPM (Node Package Manager) in Ubuntu.
  2. Update Node.js Version using NVM (Node Version Manager) in Ubuntu.


So we require any Debian distributors like Ubuntu, Linux Mint etc. here we are using a Ubuntu 20.04 System.

Also, we require sudo access, to install NPM module and NVM package.

Update Node.js Version Using Node Package Manager(NPM) in Ubuntu.

Before Update Node.js always check the current version for the node and NPM command use -v option.

$ node -v
$ npm -v 

So now we will install n module in Node.js via NPM, n module manages the version for the Node.js interactively.

Update Node.js Version in Ubuntu Linux
installed n module
$ sudo npm install -g n

So we have install the n module globally, now let’s update node to stable version.

Update Node.js Version in Ubuntu Linux
Node Update Stable Version.
$ sudo n stable

So we have update the Node.js 14.17 with NPM 6.14.

if you get the error for any environment, then use -E env “PATH=$PATH” n stable with sudo command.

Update Node.js Version in Ubuntu Linux
Environment issue with n module.
$ sudo -E env "PATH=$PATH" n stable 

So this will also update the stable version for Node.js, lets update the latest version for Node.js with n module.

Update Node.js Version in Ubuntu Linux
Update to latest version
$ sudo n latest

This will update node to latest version, now the latest version is 16.9.0 and for NPM is 7.21.1,

Now we will update the version of our choice.

Now suppose we have to update Node.js to 12.0.0, so in the place of latest put the version 12.0.0.

Update Node.js Version in Ubuntu Linux
Update Version of our choice

So now we have updated the Node.js version 12.0.0 with 6.9.0 NPM, we can manage this with n module without removing any node versions.

Want to know more about n module follow the official website.

So lets move to our second method to Update Node and NPM, But before update we will look how to install NVM(Node JS Version Manager).

How to Install Node JS Version Manager (NVM) in Linux.

So now we will use NVM to install Nodejs on Linux, with the help of this we can install as many versions for the node js as want and can be easily switched within the version itself.

We can use as many node versions in our environment, so let’s download the NVM script with the help of the curl command.

Install Node.js on Ubuntu
Install nvm on Ubuntu 18.04
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

So after installation of NVM on Ubuntu, we will set the source and list the node version we have using NVM.

$ source ~/.bashrc

So let’s use the above command and use NVM command to Update Node.js Version on Ubuntu Linux.

Update Node.js Version using NVM (Node Version Manager) in Ubuntu.

So first we will list the versions for node js via NVM command in Ubuntu.

$ nvm list-remote

       v14.17.5   (LTS: Fermium)
       v14.17.6   (Latest LTS: Fermium)

let’s Update the stable version 14 for Node.js in Ubuntu by using the NVM install command.

$ nvm install v14.17.6
nvm install v14.17.6
$ nvm list

So, we have to install the nodejs 14 version on Ubuntu and check the version of node js by using node and npm commands.

$ node -v
$ npm -v
nvm install v16.6.2

So now we will install 16 versions of node js and will check the version for a node then we will switch to the older version.

$ nvm install v16.6.2
Install Node.js on Ubuntu nvm list
nvm list
$ nvm list

So we can see the node version installed is 16 on Ubuntu System.

Want to check the node version then use node -v and npm -v.

$ nvm use v14.17.6
Install Node.js on Ubuntu nvm use to switch
nvm use v14.17.6

We have Update the version for Node.js successfully, let’s check the version for the node.

$ node -v
$ npm -v

So how easily we have updated the Node and NPM packages with the two different methods, by using NPM and then by using NVM.

Thanks to read the Article, Find some useful links install Node.js on Ubuntu, Install PM2 on Linux System, Implement PM2 Clustering on Node.js, PM2 commands, Install Node.js on Ubuntu 20.04.

Find Some Useful links for to Install MongoDB on Docker. Keep Sharing and Supporting us.

One Reply to “Update Node.js Version in Ubuntu Linux”

Give your valuable time