Step 1: Install NVM
Install node version manager.
brew install nvm
Step 2: Create a directory for NVM
Step 3: Configure your environmental variables
Either create or open your
export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh
Execute the content we just pasted.
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.
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.
nvm install 6.x.x
Install Node 8.x.x
nvm install 8.x.x
Double-check your installation.
Step 6: Set Node Globally
You can set a specific version of Node as your default.
nvm alias default 12.x.x
Error Example #1
If you are having issues with
npm, then you might want to try this.
rm -rf /usr/local/lib/node_modules
brew uninstall node
Install Node version 12.
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.
Error Example #2
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! email@example.com 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 firstname.lastname@example.org 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
If you see an error like this, then checkout this StackOverflow solution