Node Version Manager is a tool that helps us install and manage all the Node.js versions that we have installed on our machine. In this tutorial, I will guide you how to install and use this tool!
Node Version Manager can run on unix, macOS, and Windows WSL with some important notes, you can see more here. In this tutorial, I will work with Node Version Manager on macOS only!
Install Node Version Manager
To install Node Version Manager, you can download the installation script at https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh and install it by executing this file.
Another way is that you can also use the curl command as follows to download and install it:
1 |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash |
By default, Node Version Manager will be installed in the “<user_home>/.nvm” directory. You can change this default directory by declaring the NVM_DIR environment variable pointing to the directory where you want it to be installed!
My example is as follows:
1 |
export NVM_DIR=/Volumes/Passport/softwares/nvm |
Now, run the curl command above, you will see the same result as me, as follows:
At this point, Node Version Manager has been downloaded and installed in the /Volumes/Passport/softwares/nvm directory on my machine.
During the installation, a configuration was added to the .bash_profile file:
to export environment variables so we can use Node Version Manager anywhere on our computer with that command line!
You can run the command “. .bash_profile” to make the above configuration take effect immediately with the Terminal you are opening or close this Terminal and open another Terminal to start using Node Version Manager!
The result when I check the installed Node.js versions using the command:
1 |
nvm ls |
of Node Version Manager on my machine as follows:
So we have successfully installed Node Version Manager!
Install Node.js
To install a version of Node.js with Node Version Manager, first, you can use the command:
1 |
nvm ls-remote |
to check all the versions of Node.js that we can install.
My results are as follows:
We can install any version of Node.js.
You can use the command:
1 |
nvm install <node.js_version> |
to install the version of Node.js you want.
For example, I installed the latest version at the time I wrote this tutorial, v22.3.0, as follows:
Node Version Manager will automatically download the Node.js version you want to install to the $NVM_DIR/versions/node folder and install it for us.
Now you can check the results using the command:
1 |
node -v |
My example is as follows:
Node Package Manager is also installed:
So we have successfully installed Node.js using Node Version Manager!
Uninstall Node.js
To uninstall any previous version of Node.js installed using Node Version Manager, you can use the command:
1 |
nvm uninstall <node.js_version> |
with node.js_version is the version of Node.js that you want to uninstall.
For example, I currently have 2 versions of Node.js installed with Node Version Manager:
To uninstall versions older than v22.5.1, I will run the following command:
So I have successfully uninstalled it guys!