If you’re using a Mac and encountering the error message “zsh: command not found: brew,” you may be frustrated when trying to launch Homebrew. Homebrew is one of the essential package management applications on macOS, but sometimes this issue can occur because the tool is not set up correctly or the installation path is lost.
If you see the “zsh: command not found: brew” error while using Homebrew, it likely means that the Terminal app can’t find the Homebrew executable. Don’t worry, as we’ll explore some potential solutions to fix this issue below. Check out how to use Homebrew to install apps on Linux and Windows.
1. Try reinstalling Homebrew.
Reinstalling Homebrew can remove any corrupted or outdated files and install a fresh copy of Homebrew. To remove Homebrew, you can follow these steps:
Open Terminal on your Mac and uninstall Homebrew by pasting the following command and pressing the key: Return:
brew uninstall --force homebrew
Type the following command and press Return To install Homebrew again:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This will download and install the latest version of Homebrew. Once you restart the Terminal app, you should be able to use the brew command without any issues.
2. Add Brew to PATH environment variable
There is a good chance that Homebrew was not added to your PATH variable during installation, which means that your shell is unable to locate the Homebrew executable.
You can fix this by manually adding Homebrew to your PATH via Terminal. It varies slightly depending on whether your Mac has an Intel processor or an Apple silicon chip. Just copy and paste the appropriate command on your Mac into the Terminal app.
If you have a Mac with Apple silicon, enter this command:
export PATH="/opt/homebrew/bin:$PATH"
If your Mac has an Intel processor, enter this command instead:
export PATH="/usr/local/bin:$PATH"
You can check if Homebrew has been successfully added to your PATH variable using the following command:
echo $PATH
This will list all the executable binary files that Terminal can find. If Homebrew is listed, Terminal was able to successfully locate the Homebrew executable. Check out how to customize the zsh prompt in Terminal on macOS.
3. Install Xcode Command Line Tools
The Xcode Command Line Tools is a package developed and maintained by Apple that contains all the debuggers, compilers, and tools included in the entire Xcode IDE. Many users have reported that Homebrew cannot run without the Xcode Command Line Tools installed. You can install it by typing the following command in Terminal and pressing Return:
xcode-select
After that, you can verify the installation using the following command:
xcode-select -p
If the installation is successful, you should get the following output after entering the command:
/Library/Developer/CommandLineTools
Homebrew offers many useful applications and is an essential utility for every power user on Mac. If you’re encountering the “zsh: command not found: brew” error, one of the troubleshooting steps we discussed above should fix the problem and allow you to enjoy the best package manager available for macOS. Now you can check out our Zsh vs Bash comparison: Choosing the right shell for programming and text management.
Get IPTV Free Trial Now