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?
![brew command not found error brew command not found error](https://code2care.org/q/fix-brew-command-not-found-mac-terminal-linux-error/images/brew command not found error.png)
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
![bash brew command not found bash brew command not found](https://code2care.org/q/fix-brew-command-not-found-mac-terminal-linux-error/images/bash brew command not found.png)
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
- Fix: grunt: command not found (Mac/Windows)
- AppleScript Example with TextEdit
- How to copy Password of Wifi on your Mac
- Install OpenJDK Java (8/11/17) versions using brew on Mac (Intel/M1/M2)
- How to check if a port is in use using terminal [Linux or macOS]
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to Remove Widgets from macOS Sonoma 14 Desktop
- Turn off Auto-Capitalization on macOS Ventura 13
- How to Go To /usr/local/bin on Mac Terminal?
- How to Open TextEdit on Mac
- Mac: How to Open Android Studio from Terminal
- How to change the default location of Mac Screenshot
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- How to install homebrew (brew) on M1 Mac
- Must Know Homebrew Commands for Mac/Linux Users
- Steps to Uninstall Roblox on Mac (macOS)
- How to change the System Settings Sidebar icon size Mac Ventura 13
- How to set Out Of Office (OOO) on Outlook for Mac [Updated 2023]
- Trigger Notification Center Message using Mac Terminal Command
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools
- How to Install Rust Language on Mac (macOS)
- How to minimize all Windows in Mac
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to make TextEdit the default text Editor on Mac
- apt-get list --installed packages in Ubuntu Linux - Ubuntu
- Fix: ValueError: unsupported pickle protocol: 5 - Python
- How to do calculations in Mac Terminal - MacOS
- Reading .xls and .xlsx Excel file using Apache POI Java Library - Java
- Spring Boot: @RequestBody not applicable to method - Java
- Bootstrap tooltip not working - Bootstrap
- How to press shortcut CTRL + ALT + DEL on Windows Remote Desktop - HowTos
- Free Unlimited Calls from MTNL & BSNL Landlines from 1st May 2015 - HowTos