You can upgrade Node js in Ubuntu without removing the existing packages. If you have already installed Node js and want to upgrade it without losing any files then it is possible. Even you can choose any specific version to update from the current version. In this post, I will show you how you can update Node js version along with npm. It will update automatically based on the Node version.
I am assuming you are ready with the below requirement before proceeding.
- An Ubuntu user with Sudo Privileges
- A terminal and command-line access
- Node js
Check the Current Version of Node Js
Before Upgrade Node Version Ubuntu, please check the current version using the below command. Open the terminal and hit the command.
It will return the currently installed version of Node js.
You can see here, I have Node v15.14.0. Now, I want to upgrade it to 16.
How to Install and Configure pgAdmin 4 in Ubuntu 20.04
Upgrade Node Js in Ubuntu
For updating the Node version, please follow these steps.
Initially, you have to clean the cache of the npm package from your system. Therefore, hit the below command.
npm cache clean -f
It will clean the cache forcibly from your system.
In the second step, you have to install npm globally using the below command.
sudo npm install -g n
In the third step, you have to install the stable release of Node js. Therefore, hit the below command.
sudo n stable
You can check the official website of Node js to check the latest and stable release as well.
Lastly, you have to install the latest node version. Here, you can specify the version as well.
How to Configure Apache Virtual Host in Ubuntu 20.04
Update Node to a Specific Version
You can hit the below command to update the latest version of Node js.
sudo n latest
Also, you can install a specific version by giving the version in the flag.
sudo n 16.13.2
Here, I have installed the current stable version for now which is 16.13.2 as per the Node official website.
So, in the result, you can check Node specified version is installed.
You can check the current Node version now.
In the result, you can see. Now, I have the updated release of Node js.
I hope this will be helpful for you in upgrading the Node version in Linux distribution.
Himansu Sukhla says
Informative article, Thanks