If you're a node JS developer who has been working in the industry for a long time, you should have to work with different projects that use different versions of node JS. Every time you are working on such a project, are you going to uninstall and re-install the relevant version of node JS? or are you going to create separate environments for each project.
But there is an easier way now.
NVM to the rescue
Using nvm
, you can install multiple node JS versions on your computer without extra effort.
NVM was created to use on Linux systems, but there is an alternative solution for Windows OS.
Linux Setup
Installing nvm on Linux is very easy. You just need to follow the installation steps mentioned in the docs
Run the following command in your Linux terminal
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
This script will automatically export and set the necessary path variables.
After the script runs successfully, open a new terminal session and type nvm
. You should be able to see the nvm help page
Windows Setup
To configure nvm on windows, we can use nvm-windows library. This is pretty much similar to nvm but not the exact copy of it.
Download the latest version of nvm-windows from the releases page
After downloading install the nvm by using nvm-setup.exe
If you get a confirmation message like this, accept it. It will allow the already installed versions of node js to be managed by nvm.
Once it is successfully installed, open a new terminal session and type nvm
. you should be able to see the nvm help page.
!!! IMPORTANT !!!
It is important to close any already running terminal sessions and open a new terminal to check the installation.
Remember when running nvm install or nvm use, Windows usually requires administrative rights (to create symlinks).
Basic Commands
Now lets see some basic commands that will be helpful in version management.
nvm current
This command will show the active node JS version.
nvm install
This can be used to install specific version of node JS in your computer.
Windows OS will require administrative rights to perform this action.
Examples
nvm install 17.5.0
this will install version 17.5.0 of node JS in your computer.
nvm install lts
This will install LTS version of node JS.
nvm list
This will show the currently installed versions of node JS.
Run nvm list available
to list all available node JS versions to install.
nvm use xx.xx.xx
This will tell the nvm to use specific version of node JS.
Windows OS will require administrative rights to perform this action.
Example
nvm use 16.14.0
This will use specific version of 16.14.0.
Lot more commands are available in the docs.
Another good tool to manage JavaScript toolchains is volta. Let's see this in my next tutorial
Top comments (0)