- Homebrew should be installed (Command line tools for Xcode are included).
-
Install
nvmvia Homebrew$
brew install nvm -
Add following line to your profile. (
.profileor.zshrcor.zprofile)# NVM export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh
-
Close and open your terminal again. Or Choose one from the following command once for reload your profile. (
.profileor.zshrcor.zprofile)Example
- $
source ~/.profile - $
source ~/.zshrc - $
source ~/.zprofile
- $
-
Verify
nvmis installed$
nvm --version -
Check all available version by this command
$
nvm ls-remote -
Install NodeJS (Recommended to install LTS version. Current LTS is Fermium)
$
nvm install --lts=Fermium -
Check installed NodeJS in your machine.
$
nvm ls -
Set global nodejs version to environment.
$
nvm use default
See more about nvm : https://github.com/creationix/nvm
-
Install
yarnvia Homebrew$
brew install yarn -
Remove
nodedependencies from Homebrew$
brew uninstall node --ignore-dependencies -
Checkout
nodein environment$PATH$
which nodeIt should be return =>
/User/<your-user-name>/.nvm/versions/node/<latest-node-lts-version>/bin/node -
Checkout
brew doctorthere should show message WARNING missing yarn dependencies$
brew doctor -
Create blank folder and create symbol link
nodefolder fromnvmforyarnin Homebrew.$
nvm current=> v14.15.0 (Latest LTS: Fermium) (This should be Global node version)$
mkdir /usr/local/Cellar/node$
ln -s ~/.nvm/versions/node/$(nvm current)/ /usr/local/Cellar/node -
Overwrite
node, npm and npxfrom linkednodein/usr/local/Cellar/nodeto/usr/local/bin/homebrew$
brew link --overwrite node -
Checkout
ls -la /usr/local/binto see overwritednode, npm and npx -
Checkout
brew doctoragain. There shouldn't have WARNING message.$
brew doctor -
Prevent Homebrew upgrading node version
$
brew pin node -
Enjoy ! ❤️
-
Checkout
nvmfor to usenodeversion (For this example case I will use LTS Fermium)$
nvm list$ nvm list -> v12.13.1 system default -> 12.13.1 (-> v12.13.1) node -> stable (-> v12.13.1) (default) stable -> 12.13 (-> v12.13.1) (default) iojs -> N/A (default) unstable -> N/A (default) lts/* -> lts/erbium (-> v12.13.1) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.16.2 (-> N/A) lts/dubnium -> v10.17.0 (-> N/A) lts/erbium -> v12.13.1
* See more about
nvm: https://github.com/creationix/nvm -
Remove the symbol link which we linked
nodein Homebrew/usr/local/Cellar/node$
rm -rf /usr/local/Cellar/node -
Unpin
nodein Homebrew for upgradingyarn$
brew unpin node -
Upgrade
yarn$
brew upgrade yarn -
Continue on Part B 2. - 10. steps again.