Node.js is very active in the development and you may receive news about the new release almost every month. There are times when we need to maintain multiple versions of Node with the flexibility to switch between versions without going through the hassle of installation.
Enter Node helper or n.
Node helper is a dependency that allows you to switch between different versions of Node.js
If you want to use it, you need to have at least a node package manager or npm installed in your system.
For detailed tuitorial on NPM, check out: A Beginner’s Guide to Node Package Manager
Here is what you need to do step by step to update NodeJS to any version you want:
Step 1: Clean the NPM cache
sudo npm cache clean -f
This command is used to clear the cache of the npm and the “-f” flag shows that we are forcing the system to delete the cache. Running this command is useful for freeing up disk space and removing corrupted files. If you are not running this command you end up getting an error to run this.
Step 2: Install node helper (n) globally using the following command
sudo npm install -g n
This command will install the n module in the directory where package.json is defined. Additional the “-g” flag instructs it to install in the global node_modules folder as well, so we can use it directly anywhere
Install the Latest Version of Node
Once node helper is installed, you can get the latest stable version using the below command:
sudo n stable
Install a Specific Node.js Version
If you want a specific version like we needed 8.0.0 then you can do this by running the following command:
sudo n 8.0.0
After the upgrade, you can check the latest installed version of the Node using node –version or node -v.
Switch Between Different Versions of Node.js
If you want to switch to a different NodeJS version, just type n in the terminal and you should see its versions listed. Use the arrow keys to choose the version and press enter.
We have also demonstrated this package in production servers. The performance is the same, you can definitely use it.
You can install or switch between node.js versions using a thirty-party node helper (i.e. n) module. This module gives you a way to install the latest node version or a specific version and also allows you to switch between them, which is really cool. To use this package you just need to install it using npm.
We hope now you have got enough idea about how to update the node to any version using Npm. One of the best ways to understand this package better is to try it, so next time when you want to use any other version of Node, use this package for super-fast installation rather than manually install it from the website.