I have installed Homebrew using:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Why is the brew
command not found?
(base) rags@Rageshs-Mac-mini ~ % brew help
zsh: command not found: brew
My $PATH
variable according to the shell:
(base) rags@Rageshs-Mac-mini ~ % echo $path
/Users/rags/opt/anaconda3/bin /Users/rags/opt/anaconda3/condabin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/Apple/usr/bin
Best Answer
Homebrew isn't included in your
$PATH
variable, which is the cause of the shell not finding thebrew
command.To fix this, you must edit your shell startup script,
.zshrc
. The Homebrew installer doesn't make this edit, but rather instructs the user to do it, which you probably missed.Add the following line to
.zshrc
:You can either add it with a text editor or by executing a shell command:
Now, reload the shell by opening a new shell window and you should be good to go.
Explanation
The lines in
.zshrc
are executed each time you open a new shell.When the shell reaches the line
it will at first execute
, that is, executing the
brew
binary, given with its full path, withshellenv
provided as an argument. Fromman brew
:Indeed, the output of
brew shellenv
is:So in effect, the shell startup script executes
eval $(...)
, with...
replaced by the lines above.