I got a new MacBook Pro with M2 chip last week. As a web programmer, I needed to install php on macOS. Followed by the php.net provided install instruction, I installed php on macOS with homebrew.
After installing homebrew, I used the command “brew install php”, but got an error message: “zsh: command not found: brew”.
Here is the solution that I fix this problem.
Place brew in zshrc $PATH:
echo “export PATH=/opt/homebrew/bin:$PATH” >> ~/.zshrc
Then, repair brew:
brew doctor
The Terminal still shows the error message.
I try manually adding the following line to the .zshrc file:
eval $(/opt/homebrew/bin/brew shellenv)
Or add this to the zshrc with a single command:
echo “eval $(/opt/homebrew/bin/brew shellenv)” >> ~/.zshrc
Then, run “brew doctor” again.
The Terminal prompts: “Your system is ready to brew”.
Finally, I can install php by “brew install php”.
Reference: