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
2
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

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
2
rm -rf /usr/local/lib/node_modules
brew uninstall node

Install Node version 12.

1
2
3
brew install node@12
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fetching: https://registry.npmjs.org/npm/-/npm-6.4.1.tgz
up to date in 0.027s
sh: rimraf: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! npm@6.4.1 prepare: `node bin/npm-cli.js --no-audit --no-timing prune --prefix=. --no-global && rimraf test/*/*/node_modules && make -j4 doc`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the npm@6.4.1 prepare script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/myaccount/.npm/_logs/*-debug.log
npm ERR! code E404
npm ERR! 404 Not Found: 0.99s@latest
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/myaccount/.npm/_logs/*-debug.log
It failed