The "command not found: brew" error occurs because the Homebrew executable is installed on your disk but its location is not listed in your system's PATH environment variable. To fix this, you must add the Homebrew binary folder to your shell configuration file (usually .zprofile or .zshrc) so the Terminal knows where to look when you type the brew command. If you have not installed Homebrew yet, you must run the official installation script from brew.sh first.

What You'll Need

  • A Mac running macOS.
  • An active internet connection.
  • Administrator privileges (the ability to enter your Mac login password in the Terminal).
  • The Terminal app (found in Applications > Utilities).

Step-by-Step

  1. Open the Terminal: Press Command + Space to open Spotlight, type "Terminal", and press Enter.
  2. Verify Installation: Before adjusting paths, check if Homebrew actually exists on your machine. Run the following command:
    ls /opt/homebrew/bin/brew (for Apple Silicon M1/M2/M3 Macs)
    ls /usr/local/bin/brew (for Intel Macs)
    If the terminal returns the path to the file, Homebrew is installed but not linked. If it says "No such file or directory", you need to install Homebrew first by pasting the installation script from the official brew.sh website into your terminal.
  3. Identify Your Shell: Most modern Macs use Zsh by default, but older ones use Bash. To confirm, type echo $SHELL. If the output is /bin/zsh, you will edit your .zprofile. If it is /bin/bash, you will edit .bash_profile.
  4. Add Homebrew to your PATH (Apple Silicon): For Macs with M-series chips, Homebrew installs to /opt/homebrew. Run these two commands one after the other. Replace "your_username" with your actual macOS short name, or use the $USER variable as shown:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
    The first command permanently writes the configuration to your profile file so it works every time you restart the computer. The second command activates the path for your current open terminal window.
  5. Add Homebrew to your PATH (Intel): For older Intel-based Macs, Homebrew usually installs to /usr/local. Run the following:
    echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zprofile
    source ~/.zprofile
  6. Test the Command: Now, type brew help. If you see a list of available commands instead of "command not found", the issue is resolved.
  7. Verify Version: Run brew --version to ensure the installation is current and functioning correctly.

Common Mistakes

One of the most frequent mistakes is forgetting to run the "eval" or "source" command after adding the line to the profile file. Adding a line to .zprofile tells the Mac what to do the next time the terminal opens, but it does not affect the window you currently have open. Many users assume the fix didn't work and keep adding the same line to their config file repeatedly, creating a cluttered profile.

Another common error is mixing up the paths between Intel and Apple Silicon Macs. Apple Silicon Macs use /opt/homebrew, while Intel Macs use /usr/local. If you copy a guide written for an Intel Mac while using an M2 MacBook, the paths will be wrong, and the "command not found" error will persist because the system is looking in a folder that does not exist on your architecture.

Users also frequently mistake the password prompt for a frozen screen. When you run the installation script or certain brew commands, the Terminal will ask for your password. When you type, no characters (stars or dots) will appear. This is a security feature of the Unix terminal. You must type your password blindly and press Enter.

Tips

To keep your Homebrew installation healthy, run brew doctor regularly. This command scans your system for common configuration issues, outdated paths, or conflicting software and provides specific instructions on how to fix them. It is the best way to prevent the "command not found" error from returning after a macOS system update.

If you frequently switch between different shells (like Zsh and Bash), it is a good idea to add the PATH export to both .zshrc and .bash_profile. This ensures that no matter which environment you launch, the brew command remains available.

Use brew update before installing new packages. This ensures you are pulling the latest formulas from the Homebrew repository, which reduces the chance of installation errors caused by deprecated dependencies.

Troubleshooting

If you have followed the steps and still see "command not found", first check for syntax errors in your configuration file. Open the file by typing nano ~/.zprofile. Look for the line you added; ensure there are no accidental spaces at the beginning of the line and that the quotation marks are straight quotes, not "curly" or "smart" quotes often created by text editors like TextEdit. Save and exit by pressing Control+O, Enter, and Control+X.

If the file looks correct but the command still fails, try restarting the Terminal app entirely. Quit the app (Command+Q) and reopen it. This forces the shell to reload the .zprofile file from scratch.

In cases where the installation seems corrupted, you can perform a clean reinstall. First, run the uninstall script provided by the Homebrew documentation. After uninstalling, restart your Mac to clear any cached paths. Then, run the installation script again. Pay close attention to the "Next steps" section at the end of the installation output; the installer explicitly prints the exact commands you need to copy and paste to fix the PATH for your specific machine.

If you receive a "Permission Denied" error when trying to edit your profile, use sudo before the command, although this is rarely necessary for files in your own home directory (~/). Ensure your user account has Administrator privileges in System Settings > Users & Groups.

Frequently Asked Questions

Why did brew stop working after a macOS update?

macOS updates can sometimes reset system environment variables or change the default shell. If this happens, you simply need to re-run the shellenv commands listed in the step-by-step section to relink the binary folder to your current shell session.

Do I need to do this every time I open the Terminal?

No. By adding the command to your .zprofile or .zshrc file, you are making the change permanent. The shell reads these files every time a new session starts, automatically loading the Homebrew path into memory.

What is the difference between .zshrc and .zprofile?

Both are configuration files for the Zsh shell. .zprofile is typically read during login shells, while .zshrc is read for interactive shells. For Homebrew, adding the path to .zprofile is the standard recommendation for macOS, but adding it to .zshrc also works for most users.

Can I install Homebrew without using the Terminal?

No. Homebrew is a command-line package manager designed specifically to be managed via the Terminal. While there are third-party graphical wrappers, the official and most stable way to install and maintain it is through the command line.

Is it safe to add lines to my .zprofile file?

Yes, as long as you are using the official commands from brew.sh. Adding a PATH variable simply tells the computer where to look for software; it does not alter your system's core security settings or delete your data.

How do I know if I have an Intel or Apple Silicon Mac?

Click the Apple menu in the top-left corner of your screen and select About This Mac. Look at the "Processor" or "Chip" section. If it says Intel, you have an Intel Mac. If it says Apple M1, M2, or M3, you have Apple Silicon.