Written by
Jenny ZengHomebrew is a popular package manager for macOS, typically used to install software and manage dependencies. If you need to use it but aren't familiar with it, you may encounter the "command not found" error when running it. The message should read "zsh: command not found: brew" or "bash: command not found: brew," depending on the shell environment.
In this article, we'll explain the possible causes of the error and help you fix brew command not found on Mac M1, M2, M3, M4, T2, and Intel.
Why is brew command not found on Mac?
If you get the "command not found: brew" error when trying to run brew on your Mac, it usually means that Homebrew is not installed or the system can't find it in the directory paths where it expects to locate commands.
Here are a few common reasons why this might happen:
- Homebrew is not installed: You might not have installed Homebrew on your Mac yet. It's not included by default, so you'll need to install it manually.
- Homebrew's binary directory is not in your PATH: When you install Homebrew, it puts the executable (brew) in a directory like /opt/homebrew/bin or /usr/local/bin. If this directory isn't added to your PATH environment variable, your terminal won't know where to look for the brew command.
- Corrupted or incomplete installation: Sometimes, during installation or updates, something can go wrong, leading to an incomplete or corrupted Homebrew setup. This can make the brew command unavailable.
Share the reasons for brew command not found on Mac!
How to fix brew command not found on Mac?
Here are several ways you can fix the "brew command not found" issue on macOS Sequoia, macOS Sonoma, macOS Ventura, macOS Monterey, macOS Big Sur, macOS Catalina, and earlier versions:
Fix 1: Install Homebrew if you haven't
If Homebrew isn't installed on your Mac, installing it is the easiest way to resolve the issue. To do this:
- Open Terminal.
- Input the following command and press Enter./bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Type your password and press Enter.
- Press Enter again to install Homebrew on Mac.
- Wait for the installation to be complete.
- After installation, try running the brew command again to see if it's recognized.
Fix 2: Add Homebrew to Your PATH
If Homebrew exists on your Mac but the "command not found brew" error still appears, it might not be in your system's PATH, which is a list of directories Terminal looks through to find commands. To add the directory to the Path:
- Open Terminal.
- Type the command below and press Enter.echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
This will append the line export PATH=/opt/homebrew/bin:$PATH to your .zshrc file, which is the configuration file for the Zsh shell (the default on macOS versions starting from Catalina). It will also add Homebrew's installation directory (/opt/homebrew/bin) to your PATH so that Terminal can find the brew command.
Fix 3: fix brew command not found after installing Oh My Zsh
If the error occurs after installing Oh My Zsh, you should add the line eval $(/opt/homebrew/bin/brew shellenv) to your zshrc with the following command:
echo "eval $(/opt/homebrew/bin/brew shellenv)" >> ~/.zshrc
This command sets up your Terminal to recognize Homebrew and ensures that it is correctly integrated into your system.
When you run this, every new Terminal session will automatically configure the environment needed for Homebrew to work, such as updating the PATH to include Homebrew's directories. This makes it easier to use brew without needing to manually configure environment variables every time you start a Terminal window.
Now that you know how to fix brew command not found on macOS, share the solutions with others!