Homebrew relies on shell startup files to put its brew command and installed package binaries in the shell search path. When a fresh terminal cannot find brew, or it finds the wrong Homebrew prefix, the shell needs to load Homebrew's shellenv output during startup.
The brew shellenv command prints shell-specific export statements for $PATH, $MANPATH, $INFOPATH, and Homebrew's own prefix variables. Evaluating that output from the correct startup file lets each new shell use the active Homebrew installation without copying every generated directory by hand.
Apple Silicon macOS normally uses /opt/homebrew and zsh, while Intel macOS uses /usr/local and Linux or WSL uses /home/linuxbrew/.linuxbrew. Replace the prefix and shell name before editing the startup file when your Homebrew install uses a different combination.
Related: How to find a Homebrew package prefix
Related: How to fix Homebrew permission errors
Related: How to run brew doctor
$ /opt/homebrew/bin/brew --prefix /opt/homebrew
Use /usr/local/bin/brew on Intel macOS or /home/linuxbrew/.linuxbrew/bin/brew on Linux and WSL when that is the installed Homebrew binary.
Related: How to find a Homebrew package prefix
$ /opt/homebrew/bin/brew shellenv zsh
export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
fpath[1,0]="/opt/homebrew/share/zsh/site-functions";
export FPATH;
eval "$(/usr/bin/env PATH_HELPER_ROOT="/opt/homebrew" /usr/libexec/path_helper -s)"
[ -z "${MANPATH-}" ] || export MANPATH=":${MANPATH#:}";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";
Pass bash instead of zsh when Bash owns the startup file. For fish or pwsh, use the syntax printed by brew shellenv fish or brew shellenv pwsh instead of the zsh eval line.
$ nano ~/.zprofile
Use ~/.zshrc for zsh on Linux, ~/.bash_profile for Bash on macOS, or ~/.bashrc for Bash on Linux.
eval "$(/opt/homebrew/bin/brew shellenv zsh)"
Do not paste zsh syntax into a fish or pwsh startup file. Print brew shellenv fish or brew shellenv pwsh for that shell and use the syntax it returns.
$ source ~/.zprofile
Opening a new terminal window also loads the login profile on macOS.
$ command -v brew /opt/homebrew/bin/brew
$ brew --prefix /opt/homebrew
If the output still points to another prefix, remove duplicate shellenv lines from older startup files and open a new login shell.