Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fix Command Not Found Brew Error on Mac

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To fix the "command not found: brew" error, you must add the Homebrew installation directory to your system's PATH environment variable. This happens because the terminal does not know where the brew executable is located, even if the installation finished successfully. Depending on your Mac processor (Intel or Apple Silicon), the path differs, and you must run a few specific commands in your terminal to tell macOS where to find Homebrew.

What You'll Need

  • A Mac with macOS installed.
  • An active internet connection.
  • The Terminal app (found in Applications > Utilities).
  • Your Mac user password (you will be prompted for this during the process).

Step-by-Step

  1. Identify your processor type: Click the Apple menu in the top-left corner of your screen and select About This Mac. Check if it says "Processor" (Intel) or "Chip" (Apple M1, M2, M3, etc.). This determines which path you need to add.
  2. Open the Terminal: Press Command + Space, type "Terminal", and press Enter.
  3. Determine your shell: Type echo $SHELL and press Enter. Most modern Macs use /bin/zsh. If you see /bin/bash, you will need to edit .bash_profile instead of .zprofile.
  4. Add Homebrew to your PATH (Apple Silicon): If you have an Apple chip, run the following three commands one by one. Replace with your actual macOS short name if the command does not automatically resolve it, though the $(whoami) variable usually handles this: echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" Note: The first command adds the configuration to your profile file so it persists after rebooting; the second command activates it for your current session.
  5. Add Homebrew to your PATH (Intel): If you have an Intel processor, run these commands: echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zprofile source ~/.zprofile
  6. Verify the fix: Type brew help and press Enter. If you see a list of Homebrew commands instead of an error, the issue is resolved.
  7. Run the doctor: To ensure everything is configured correctly and there are no other system conflicts, run brew doctor. Follow any additional instructions provided by the tool.

Common Mistakes

  • Using the wrong path: Applying the /opt/homebrew path to an Intel Mac or the /usr/local path to an Apple Silicon Mac will not work. Always verify your chip type first.
  • Forgetting to source the profile: Adding the line to .zprofile only affects future terminal sessions. If you don't run the eval or source command, you will still see the error until you restart the terminal.
  • Typing errors in the command: A missing quote or a misplaced space in the echo command can corrupt your profile file. If you suspect a typo, open the file with nano ~/.zprofile to manually check the text.

Tips

  • Use Zsh: If you are on an older version of macOS using Bash, consider switching to Zsh (the current macOS default) by running chsh -s /bin/zsh.
  • Keep Homebrew Updated: Once the command is working, regularly run brew update to keep your package manager and formulas current.
  • Check Permissions: If you encounter "Permission Denied" errors during installation, avoid using sudo brew. Homebrew is designed to run without root privileges.

Troubleshooting

If you followed the steps and still see "command not found", try these steps in order:

  1. Restart Terminal: Completely quit the Terminal app (Command + Q) and reopen it to force it to reload the profile.
  2. Check if Homebrew is actually installed: Run ls /opt/homebrew/bin/brew (Apple Silicon) or ls /usr/local/bin/brew (Intel). If the terminal says "No such file or directory", Homebrew was never installed. Re-run the official installation script from brew.sh.
  3. Check for multiple profile files: Some users have both .zprofile and .zshrc. If .zprofile isn't working, try adding the same eval line to ~/.zshrc using the echo command.
  4. Manual Path Check: Type echo $PATH. Look for /opt/homebrew/bin or /usr/local/bin in the output. If it is missing, the echo >> ~/.zprofile command did not execute correctly.

Frequently Asked Questions

Why did this happen after a successful installation?

The Homebrew installer downloads the files to your disk, but it cannot always automatically modify your shell's configuration file due to system permissions. You must manually tell the shell where the binaries are located.

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

No. By adding the command to .zprofile or .zshrc, the path is loaded automatically every time a new terminal session starts.

Is it safe to add lines to my .zprofile?

Yes, as long as you are using the official Homebrew paths. This is the standard way to manage environment variables in Unix-based systems like macOS.

What is the difference between /opt/homebrew and /usr/local?

Apple Silicon Macs use /opt/homebrew to avoid conflicts with the system's pre-installed software and to maintain a clear separation from Intel-based binaries. Intel Macs use /usr/local as the traditional location.

Can I fix this without using the terminal?

No. Because Homebrew is a command-line tool and the PATH is a shell configuration, the fix must be applied via the terminal or a text editor modifying the hidden configuration files in your home directory.