Install NVM On Mac With Brew

Image for post
Image for post
Showing Currently Installed Node Versions Using NVM

So yesterday I was in the process of installing dependencies for a Gatsby tutorial project when I hit some build errors while installing NPM packages.

After pouring over Github issues, I found a work around that was rather wonky. An alternative to this I saw was to on Node version 11.

A friend’s suggestion to try NVM to easily switch between Node environments popped into my head. I’ll admit I was hesitant that I would fall into a serious rabbit hole and divert too much time away from my task at hand, but it turned out to be really simple so I thought I’d share it with you all.

If you already have node installed, uninstall it. I had Node installed via Homebrew and found that I needed to first uninstall node.

brew uninstall --ignore-dependencies node
brew uninstall --force node

If you don’t have Homebrew installed, install it now.

After installing it, update the Homebrew package list and install NVM.

brew update
brew install nvm

Next, create a directory for NVM.

mkdir ~/.nvm

Now add these lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or later)

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

Echoing $NVM_DIR should now return your NVM directory

jamesauble@James-MacBook-Air:$ echo $NVM_DIR
/Users/jamesauble/.nvm

Now running should return nvm’s options.

To see what Node versions are available to install run:

nvm ls-remote

For me, I just needed the latest point release of Node version 11 so I ran

nvm install 11

After installing you can verify what is installed with

nvm ls

If you have multiple versions and you want to specify which version you would like to use, simply use:

nvm use 11

to use Node version 11.

Switching back to, let’s say, version 12 would be as easy as

After switching to node version 11, all my packages installed properly and all was right in the universe!

Written by

Front-end Web Developer. Language lover. Traveler. Dude.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store