You are seeing the error because Homebrew is not in your system’s PATH variable. To fix this, you must add Homebrew’s installation path to your shell configuration file. The solution works by editing your shell profile (usually ~/.zshrc for macOS Catalina and later, or ~/.bash_profile for older systems) and then restarting your terminal or running a source command.

What You'll Need

  • A computer running macOS or Linux.
  • Access to the terminal application.
  • Basic understanding of editing text files using a text editor.

Step-by-Step

  1. Identify your shell. Open the Terminal application. Type echo $SHELL and press Enter. If it returns /bin/zsh, you are using the Zsh shell (standard on newer macOS). If it returns /bin/bash, you are using the Bash shell. This determines which configuration file you must edit.
  2. Check the Homebrew installation path. Run which brew in the terminal. This command tells you exactly where Homebrew is installed on your system. The output will look something like /opt/homebrew/bin/brew (Apple Silicon Mac) or /usr/local/bin/brew (Intel Mac). You will need this path in the next step.
  3. Edit the shell configuration file. Open your profile file in a text editor. For Zsh users, run open -e ~/.zshrc. For Bash users, run open -e ~/.bash_profile. This opens the file in the default text editor (TextEdit or TextEdit in Plain Text mode depending on your settings). If the file does not exist, the editor will create it.
  4. Add the Homebrew path to the file. In the opened text file, add the following line to the bottom of the document. Replace /path/to/your/homebrew with the path you found in step 2 (e.g., /opt/homebrew/bin or /usr/local/bin).
    export PATH="/path/to/your/homebrew/bin:$PATH"
    This line tells your operating system to look in the Homebrew directory for executable files before it looks anywhere else.
  5. Save and close the file. In the text editor, go to File > Save. Close the editor window completely.
  6. Reload the configuration. Return to the Terminal window. To apply the changes immediately without restarting the terminal, type source ~/.zshrc (if using Zsh) or source ~/.bash_profile (if using Bash) and press Enter. If you prefer, you can simply close the Terminal window and open a new one - the changes will be loaded automatically.
  7. Verify the fix. Type brew doctor and press Enter. If the error is resolved, the command will run without output or display a message indicating Homebrew is correctly installed. If the error persists, proceed to the Troubleshooting section.

Common Mistakes

One of the most frequent errors is editing the wrong configuration file. If you are using Zsh but edit ~/.bash_profile, the terminal will not load the new path. Always check your shell first with echo $SHELL. Another mistake is forgetting the $PATH at the end of the export line. Without this, you are only adding the Homebrew path but removing the rest of your system’s default path, which can break other tools.

Tips

When editing the configuration file, it is often safer to add the line at the very bottom rather than trying to insert it into an existing list of paths. This ensures you do not accidentally overwrite existing settings. If you are unsure which shell you are using, it is safe to add the export line to both ~/.zshrc and ~/.bash_profile, though this is redundant on a fresh system.

Troubleshooting

If the brew command still returns command not found after following the steps above, check if Homebrew was actually installed. Run the installer script again to ensure it completed successfully. If Homebrew is installed but the path is still missing, ensure you used the correct path from step 2. On Apple Silicon Macs, the path is typically /opt/homebrew/bin, while on Intel Macs, it is /usr/local/bin. A common cause of failure is editing the file in Rich Text mode (RTF) instead of Plain Text; ensure the editor is set to Plain Text mode to avoid saving invisible character codes.

Frequently Asked Questions

Why does my terminal say command not found for Homebrew?

Your shell does not know where Homebrew is located because the directory containing the brew executable has not been added to your system’s PATH environment variable.

Do I need to restart my computer?

No. You only need to restart your terminal session. You can do this by closing and reopening the Terminal window, or by running the source command to reload the configuration file in the current session.

What is the difference between ~/.zshrc and ~/.bash_profile?

These files store different shell configurations. Zsh is the default shell on macOS Catalina and later, so it looks at ~/.zshrc. Older macOS versions and Linux systems often use Bash, looking at ~/.bash_profile or ~/.bashrc.

Can I install Homebrew to a custom directory?

Yes, Homebrew can be installed to a custom prefix by adding the HOMEBREW_PREFIX environment variable to your shell configuration before running the install command.

Is there a graphical way to fix this?

No. The PATH variable is a system-level configuration that must be edited via the command line in the terminal.