As a runtime environment, node.js helps create fast and extensible applications. And not only the applications are fast - so are the updates. They come on once every few weeks and enhance security, stability, as well as add some new features.
And if you wish to get an update, there's actually a very simple way to do so. Here are the ways how to update Node on various operating systems
1. How to upgrade node using pre-installed Node Package Manager (npm)
You can also use Node Package Manager (npm) to update your node.js. Node comes with the package manager already preinstalled - but before you update Node.js, you need to make sure you npm is at the latest version as well.
- First, you may want to find out the Node Package Manager version you have, by running an
- Once done, use
npm install [email protected] -gcommand to install the latest Node Package Manager version available.
- Finally, use
npm -vcommand to confirm whether your new Node Package Manager was successfully installed.
To update node.js using Node Package Manager, use Node Package Manager’s n module. The following code will help you clear cache from your Node Package Manager and install the latest node.js version
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Use this command n latest to make sure you install the newest version. You may also want to use n #.#.# command if you’re looking for a specific version of node.js.
2. How to update node js with Node Version Manager (nvm):
Node Version Manager presents a perfect way to update your node.js. Run a C++ compiler and the build-essential and libssl-dev packages, like this:
sudo apt-get update
sudo apt-get install build-essential checkinstall libssl-dev
Now, you can update Node using cURL. Here's the install script you should be using:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
You can use Wget as well. Here's the script:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
Afterward, use the command
command -v nvm to find out whether the installation process of your new and up-to-date Node Version Manager was a success or not.
If the installation was successful,
command -v nvm will output Node Version Manager. If not, and you're getting
nvm: command not found, simply close and reopen the terminal, and try the
command -v nvm again. This should do the trick.
After you’re done installing your new nvm, installing new node.js versions should be easy. Use this command nvm ls to find out previously installed node.js versions. Also, use ls-remote to discover node.js versions available for installation
Use nvm install #.#.# command to download and install a new version of node.js.
3. How to upgrade node using Binary Packages:
Well, to update node Linux visit nodejs.org and click on the download link to get 64-bit (×86) or 32-bit binary file. Use the console to download the file and make sure that it is the latest version to upgrade node perfectly.
Very important: first unpack the file using xz-utils, and install it using
sudo apt-get install xz-utils. Next, complete the installation of the binary code using this code:
tar -C /usr/local -strip-comp.
4. How to Upgrade Node on Windows and MacOS
Leave it to Linux users to do things the hard way. You can still do this the hard way, through the terminal (but why would you?). If you're using either Windows or Mac, everything is as simple as running an installation wizard.
To upgrade Node on Windows and Mac, simply visit the Node.js homepage and choose your operating system. From there, a wizard will magically update your Node, and replace the older version with the new one.
Are you a Linux user, and are looking for a similar experience? Well, there might still be a way out for you.
On desktop environments such as Gnome or Unity, you can install and update Node using the graphically interfaced package manager.
One of such examples is Snap Store (on Gnome).
You have finished updating Node js! What now?
The truth is simple - the Node.js modules become outdated all the time and should be updated frequently. The obsolete versions of node.js seriously limit you. Older versions will become incompatible with tools like SQL, and cause the application performance to go down. And yet still, many developers start doing updates only when the things they have stopped working.
That's not good enough. As the legendary software engineer Robert C. Martin once said: "It is not just enough for the code to work”.
You have to make things perfect - and keeping constant Node.js updates is a great step towards that.