Manage Node versions on Mac with NVM

Photo by Artem Sapegin on Unsplash

If you are using a Mac, you most probably use Homebrew to manage your Node.js installation. However, if you want to use different Node versions for different projects, using Node Version Manager (NVM) to switch between versions would make your life easier.

  1. Remove existing Node installed via Homebrew

This is important to make sure all your Node installations are managed through NVM.

2. Install NVM using Homebrew

If you run into an error such as ‘Permission denied @ apply2files’, you may need to reset permissions for /usr/local as mentioned in this SO answer.

3. Set NVM home directory

Create NVM’s working directory.

Edit your shell config file to add the path to the NVM home directory. The shell config file would be ~/.bash_profile if you are using Bash, or ~./zshrc if you are using Zsh, the default shell for MacOS Catalina and later versions.

Add the following to the config file.

Close your nano editor and verify the path to the home directory.

4. Install Node using NVM

After installing, simply switch to the Node version you need to use.

And that’s it!

Thanks for reading!