2 Ways to Update or Upgrade Node.js Version in Ubuntu.

This article is for “2 Ways to Update/Upgrade Node.js version to the latest version in Ubuntu Linux Systems”.

It is an Open Source and cross-platform Application. So NodeJS can run on various platforms like Linux, Windows, and Mac.

NodeJS can be scale-up and down as per the need. Also, it handles more requests because of its single-threaded behaviour.

The biggest giant Industries like Walmart, PayPal, Netflix, etc. use 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 you can refer to the link.

So the 2 Ways to Upgrade the Node.js Version are as follows.

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

Prerequisite

Any Debian distributors like Ubuntu, Linux Mint etc. for our setup will use Ubuntu 20.04 with sudo access.


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 install the “n” module in Node.js via NPM because the “n” module manages the version for the Node.js.

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

After installation for the “n” module globally, update the node to stable version.

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

So by using the above command the stable version for Node.js 14.17 with NPM 6.14 gets upgraded.

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

Set env and install the stable version
Environment issue with n module.
$ sudo -E env "PATH=$PATH" n stable 

So the above command will also update the stable version for Node.js.

Let’s Upgrade the latest version for Node.js with the “n” module.

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

This will update the node to the latest version 16.9.0 and NPM 7.21.1.

Can you update the version of our choice?

Assume that any developer needs a Node.js 12 version to upgrade or install.

Sure can do that instead of latest put the version.

$ sudo n 12.0.0
Update Node.js Version in Ubuntu Linux
Update Version of our choice

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


Before going to the second Method have a look at “how to install NVM(Node JS Version Manager)”. Which will be very helpful to upgrade Node.js Versions.


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

So with the help of NVM can install as many versions for the node.js and switch the version as required.

Also, use as many node versions in a single environment and switch according to our needs. 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

After installation of NVM on Ubuntu, we will set the source and list the node version by using NVM command.

$ source ~/.bashrc

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


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

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

$ nvm list-remote

OUTPUT:
       v14.17.5   (LTS: Fermium)
       v14.17.6   (Latest LTS: Fermium)
        v15.0.0
        v15.0.1
        v15.1.0
        v15.2.0
        v15.2.1
        v15.3.0
        v15.4.0
        v15.5.0
        v15.5.1
        v15.6.0
        v15.7.0
        v15.8.0
        v15.9.0
       v15.10.0
       v15.11.0
       v15.12.0
       v15.13.0
       v15.14.0
        v16.0.0
        v16.1.0
        v16.2.0
        v16.3.0
        v16.4.0
        v16.4.1
        v16.4.2
        v16.5.0
        v16.6.0
        v16.6.1
        v16.6.2
        v16.7.0
        v16.8.0

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
$ node -v
$ npm -v

Let’s install the nodejs 16 version on Ubuntu and check the version of node js by using node and npm commands.

$ nvm install v16.6.2
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. Check the version with “node -v” and “npm -v”.

Let’s switch the version from 16 to 14 by using NVM command.

$ 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 NVM is very simple to use, also on a single environment we can have a multiple Node.js version.

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 “2 Ways to Update or Upgrade Node.js Version in Ubuntu.”

Give your valuable time