Install node with nvm then brew


Install Node.js first with nvm, a node version manager like n:

curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

Reload shell:

source ~/.zshrc # ~/.bashrc

Install node version 8:

nvm install node@8

The node binary can be found at:

which node # command -v node
$NVM_DIR/versions/node/v8.15.0/bin/node

Now install Node.js with homebrew:

brew install node@8 && brew link node@8 --overwrite --force

However, the default node binary is still coming from nvm:

nvm ls
-> v8.15.0
    system

To use the node binary installed by brew, you’ll need to pass the --no-use option to the nvm startup script:

 # edit line in your shell configuration (e.g., ~/.zshrc or ~/.bashrc)
-[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
+[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use  # This loads nvm

To verify that you’re using the brew installed node binary:

nvm ls
   v8.15.0
->  system
which node
/usr/local/bin/node

A nice benefit is that this speeds up the time for shell session creation.



Please support this site and join our Discord!