How to install Node on Mac using NVM and Homebrew
Version Manager makes it easy to install multiple versions of Node on a Mac. You install NVM using Homebrew, and if you don’t have Homebrew installed yet, read this article.
Step 1: Install NVM
Install node version manager.
1 | brew install nvm |
Step 2: Create a directory for NVM
1 | mkdir ~/.nvm/ |
Step 3: Configure your environmental variables
Either create or open your .bash_profile.
1 | vim ~/.bash_profile |
Paste this.
1 | export NVM_DIR=~/.nvm |
Execute the content we just pasted.
1 | source ~/.bash_profile |
Step 4: Double-check your work
If you’ve done everything correctly, you should be able to run the nvm command and ask it to list which versions node are available.
1 | nvm ls |
Step 5: Install Node
You can see a list of previously released versions of node from the NodeJS release page
Install Node 6.x.x.
1 | nvm install 6.x.x |
Install Node 8.x.x
1 | nvm install 8.x.x |
Double-check your installation.
1 | nvm ls |
Step 6: Set Node Globally
You can set a specific version of Node as your default.
1 | nvm alias default 12.x.x |
Troubleshooting
Error Example #1
If you are having issues with npm, then you might want to try this.
1 | rm -rf /usr/local/lib/node_modules |
Install Node version 12.
1 | brew install node@12 |
Add this to your local variables so that npm and global npm are usable.
1 | export PATH="$HOME/.npm-packages/bin:$PATH" |
Source
Error Example #2
1 | fetching: https://registry.npmjs.org/npm/-/npm-6.4.1.tgz |