Table of Contents
In this post, we will show you the way to manage different node.js versions in a single terminal with ease using n. n is a very useful tool to manage node.js versions interactively, yes you heard it right. It is very easy to use the tool but will help you a lot if you have to deal with different node version.
It is my personal experience to switch node version many times for different libraries as their maintainer provide the library support on different node version, in addition to that we also need to test the library on a different version of node too. In the mentioned cases n will make your life very easy.
For those who are still confused, n is a node.js management tool which helps you to install different versions of node.js on a single terminal and you can switch to any node version any time you want.
Note: Windows operating system does not support n natively. This example will only work within UBUNTU and Mac.
I think the explanation of the library is enough now let’s get started with the installation and see how to use it to manage different node.js versions.
Installation of n
n is very easy to install using npm but you can also install it using third-party installers. Here we are mentioning the npm way only as while working with node.js we already have the npm installed in our terminal. So to install then use
npm install -g n
This will install the n globally and now you are ready to use it.
Get Directory Ownership
After the installation of n, you can use it with the sudo (I hope everybody knows about sudo. If not, then please comment below) but it is suggested to take ownership of the system directories and use it without sudo. So to take the ownership run the following commands
1. Make cache folder (if missing) and take ownership
sudo mkdir -p /usr/local/n
sudo chown -R $(whoami) /usr/local/n
2. Take ownership of node install destination folders
sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share
Install Different Version of node.js using n
Now we have n installed, let’s see how to use it to install a different version of node.js
1. To install the specific version of node.js using n user
n <node Version> //Example: n 10.16.0
2. You can also use
n lts //To install newest Long Term Support official release
n latest or n current //To install the newest official release
Select node.js Version for Development
Now we have an idea about the installation of n and the installation of different versions of node.js using n, let’s see how to select particular node.js version from multiple installed node.js
First, have a look at the currently installed node.js using
now to select from multiple node.js installed just run
it will give you the list of different node.js installed with a bullet pointing to the current node.js version. You can use up/down arrow keys to select the version you want in your terminal and hit enter. It will change the current node.js version in the terminal. Have a look at the installed node.js using
This will show you the updated version of node.js
Removing any Version of node.js using n
1. If you have too many node.js version installed and want to remove any then you can use
n rm <node version> // Example n rm 0.9.4
2. To Remove all versions except the current version
Uninstallation of n
if you don’t want to use n, or switching to a different way of managing them then you can uninstall n using
This is how you can Manage different Node.js versions in a single terminal with ease using n. If you are facing any issue or have anything to share you can comment below. You can also visit the official page here to know more about the n.
Hope you liked it. 🙂