Homebrew or most commonly known as brew is a quite popular package manager when it comes to macOS the Operating System for MacBooks and Mac Computers, nevertheless it is also quite famous with Linux Operating Systems as well.
Most common brew error messages
ZSH Shell
% zsh: command not found: brew
Bash Shell
$ bash: brew: command not found
Sh Shell
$ sh: brew: command not found
Why brew: command not found error?
The most common reason for the message "brew: command not found" is either you do not have Homebrew installed on your device, or you have not set the path for it.
When you run the brew command to install a package, the terminal looks for the brew binary in certain system paths and profile files to locate brew, if it is not found, you get the brew not found error.
How to find out if the brew is installed?
As we discussed, one of the reasons could be that Brew is installed on your device but it's not set in the $PATH environment variable. You can find out if the brew binary is available or not by running the which command in a terminal,
% which -s brew
brew not found
If you get brew not found then brew is missing on your device or the path is not set.
% which -s brew
brew not found
If the brew is installed and the path is set you will get the output as where the brew is installed,
Example:bash-3.2$ which brew
/opt/homebrew/bin/brew
How to fix the brew command not found an error?
If the brew is not installed on your macOS or Linux device, you would first need to get it installed.
Installing Homebrew on macOS/Linux
- Open Terminal/Linux shell prompt the command line application on your device,
- Now visit the brew website (https://brew.sh) and look for the command with install.sh,
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Note that you should have curl command package installed as a prerequisite.
- Copy the bash command and run it on any shell: zsh, bash, or sh,
- On macOS you will be asked for a password and Xcode Command Line Tools will be installed as well which may take a while to download,
- Once the installation is complete you should see a Next Step with the below details based on which shell you are in,
==> Next steps: - Run these three commands in your terminal to add Homebrew to your PATH: echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/code2care/.zprofile echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/code2care/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"
- Check if the brew command is now available or not using the --version option,
% brew --version Homebrew 3.6.6 Homebrew/homebrew-core (git revision 9723dbb3bd5; last commit 2022-10-20)
Setting PATH for brew using command line
For Apple Silicon based M1/M2 Mac
For Macbook's running on Apple ARM based M1/M2 chip brew is installed at location /opt/homebrew/bin
ZSH Shell:echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/your-user/.zprofile
Bash Shell:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/your-user/.zprofile
For Intel based Mac
For Macs running on Intel-based chip brew is installed at location /user/local/bin
ZSH Shell:echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/your-user/.zprofile
Bash Shell:
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/your-user/.zprofile
For Linux
ZSH Shell:echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/your-user/.zprofile
Bash Shell:
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/your-user/.zprofile
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- How to show line numbers in Nano on Mac
- How to install Jupyter Notebook on macOS Sonoma
- How to Disable Remote Management using Mac Terminal
- Test internet speed using macOS Terminal command
- Docker Desktop needs privileged access macOS
- Google Search Hot Trends Screensaver for Mac OS X
- How to do calculations in Mac Terminal
- How to make TextEdit the default text Editor on Mac
- How to Show Full Website Address on Safari for Mac (Ventura/Sonoma)
- The Zsh Shell - Mac Tutorial
- Opening mac Terminal
- How to change the name of your Mac running on macOS Ventura 13
- How to find the Battery Cycle Count on macOS Ventura
- How to set an emoji as Zsh terminal prompt in macOS
- How to access Trash Folder using Mac Terminal Command
- macOS Ventura XCode Command Line Tools Installation
- Hide Bluetooth icon on Mac Menu Bar macOS Ventura 13
- How to run .sh file in Mac Terminal
- Terminal Command to get the list of available shells in macOS
- How to see Storage Information on macOS Ventura
- How to Go To /usr/local/bin on Mac Terminal?
- How to do screen recording on Mac
- How to Find File and Directory Size in Mac Terminal
- Open .bash_profile File in TextEdit using Terminal
- Remove Now Playing icon from macOS Big Sur Menu Bar
- Android Development - How to switch between two Activities - Android
- Create simple struts2 project using maven commands - Java
- Increase or Decrease macOS Sonoma Sidebar Icon and Text Size - MacOS
- How to Measure Execution Time in Jupyter Notebook Cell - Python
- Python: Convert Minutes to Hours - Python
- Where are Plugins Installed in Notepad++ - NotepadPlusPlus
- [Android Studio] Error: Missing system image on device - Android-Studio
- How to hide toolbar on Notepad++ - NotepadPlusPlus