Using nvm To Manage Node Versions
Different projects of node use different versions and being able to switch back and forth is a necessity. Luckily for us, there is nvm which allows to change and install different nvm versions easily. Here is how to get started and some quick commands.
Installing
- Using homebrew:
- Use the nvm provided install script
Commands
- Installing a node version:
- The first installed version becomes the default
- List all available node versions
- Use a particular version
Using a .nvmrc file
- You can create a
.nvmrc
file containing a node version and nvm will traverse the directory structure looking for that file too use that version.
- So then if you run
nvm use
, nvm will find that nvmrc file and switch to the node version specified.
With deeper shell integration you can have your node version change immediately when changing into that directory that contains a .nvmrc file. This makes changing node versions based on the project a breeze and totally automated.
Read more about nvm