NodeJS is one of the most popular Javascript frameworks nowadays. It has been widely accepted in the world of web development and is commonly used for developing lightweight backend servers, REST APIs, etc. Its package manager, npm
is one of the biggest repositories for Javascript libraries.
In this tutorial, we will see how to update Node JS in Ubuntu.
Prerequisites
NodeJS must be already installed on your Ubuntu machine. It is also recommended that nvm
(Node Version Manager) must be installed on your machine, so that we can update NodeJS efficiently.
Updating NodeJS using apt
If NodeJS was installed using apt
package manager in Ubuntu, it can be updated as well using the same.
sudo apt update
sudo apt install nodejs
Note: Use apt-get instead of apt on older Ubuntu versions (version 14.04 and below).
Updating NodeJS using nvm
Node Version Manager, which is actually a Bash script to efficiently manage multiple Node versions on the same system, can be used to update Node.
Node has certain versions, which are deemed ‘Long Term Support’ (LTS) releases, for which support fixes are provided up to 30 months after their release. To update NodeJS to the latest LTS version, run:
nvm install --lts
To update to the latest stable release of NodeJS (Non LTS), run:
nvm install node
To update nodeJS to a custom version instead of the latest Node release, run:
#nvm install <node_version>
#Eg. :
nvm install 13.0.0
Conclusion
We have shown two methods of updating NodeJS to the latest version in Ubuntu. There are other methods as well, eg. using Node Package Manager (npm
), however, it often tends to cause version mismatches, and hence nvm
is a proper tool meant for preventing such mismatches.
Member discussion