jakewies
jakewies

Reputation: 362

Issues installing Node via homebrew

I'm attempting to get the LTS version of node installed on my machine via homebrew but I seem to be having some issues. If I run brew install node@6 to get the latest LTS version (6.10.3), everything seems to complete with no issues. Then, if I run brew list, I will see node@6 has indeed installed. BUT, if I check which version of node is installed using node -v, I receive zsh: command not found: node. I'm pretty new to homebrew and the command line in general. Where have I gone wrong?

Any help would be greatly appreciated, and I can provide more info if requested. Thanks!

Upvotes: 5

Views: 10524

Answers (3)

Reed Dunkle
Reed Dunkle

Reputation: 3587

As indicated in the GitHub issue linked above, if you run brew info node@10 (replace node@10 with your version) it provides a line to add the non-latest node version to your path:

If you need to have node@10 first in your PATH run:
echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> ~/.zshrc

Running echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> ~/.zshrc adds a line to the bottom of my .zshrc file:

export PATH="/usr/local/opt/node@10/bin:$PATH"

If you're using Bash, it'd be your .bashrc file. I'm guessing Homebrew picks up on that, but worth double checking.

This line will add /usr/local/opt/node@10/bin to my PATH when I start my terminal. I need to restart my terminal to get immediate access. Or I can re-source the .zshrc file. I only have to do this the first time:

source ~/.zshrc

Now node works. I can verify by checking the version:

node -v
# v10.17.0

Upvotes: 2

jakewies
jakewies

Reputation: 362

For those curious, I ended up just using brew install node to install the most current version of node. Trying to install node@6 was troublesome, but it seems my struggle was pertaining to an issue where homebrew required node@6 to be linked using brew link node@6 --force. More info can be found here:

https://github.com/Homebrew/brew/issues/2220

Note that I did not try this solution.

Upvotes: 2

Tuan Anh Tran
Tuan Anh Tran

Reputation: 7237

Could you check if /usr/local/bin is in your $PATH? Also, maybe run brew doctor?

Upvotes: 0

Related Questions