Homebrew isn't included in your $PATH
variable, which is the cause of the shell not finding the brew
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
:
eval $(/opt/homebrew/bin/brew shellenv)
You can either add it with a text editor or by executing a shell command:
$ echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> $HOME/.zshrc
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
eval $(/opt/homebrew/bin/brew shellenv)
it will at first execute
/opt/homebrew/bin/brew shellenv
, that is, executing the brew
binary, given with its full path, with shellenv
provided as an argument. From man brew
:
shellenv
Print export statements. When run in a shell, this installation of
Homebrew will be added to your PATH, MANPATH, and INFOPATH.
The variables HOMEBREW_PREFIX, HOMEBREW_CELLAR and HOMEBREW_REPOSITORY
are also exported to avoid querying them multiple times. Consider
adding evaluation of this command's output to your dotfiles (e.g.
~/.profile, ~/.bash_profile, or ~/.zprofile) with: eval $(brew shel-
lenv)
Indeed, the output of brew shellenv
is:
$ brew shellenv
export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";
So in effect, the shell startup script executes eval $(...)
, with ...
replaced by the lines above.
/opt/homebrew
? If not, then the install didn't work. If there is (and I mean like a LOT of stuff), then the install might have worked but it might have failed to configure your shell properly. You mostly just need add/opt/homebrew/bin
to your $PATH in your shell config file (which could be.profile
,.bashrc
, or.zshrc
), like this: stackoverflow.com/questions/11530090/…