Yes, the issue is almost certainly that Homebrew is installed but isn't added to your shell's path, or the shell configuration file is missing the necessary code.

What You'll Need

  • A Mac running macOS (Intel or Apple Silicon) with Terminal open.
  • Administrator privileges (sudo) for a few commands.
  • Basic familiarity with the Terminal and editing text files.

Step-by-Step

  1. Verify Homebrew Installation: Open the Terminal app (found in Applications > Utilities or via Spotlight). Type the following command and press Enter. This checks if the package manager is actually present on your system.
    brew --version
    If you see a version number (e.g., Homebrew 4.x.x), the installation is intact. If you see command not found: brew, the installation was corrupted or incomplete, and you should reinstall Homebrew completely before attempting the fixes below.
  2. Identify Your Shell: Type the following command and press Enter to see which shell you are currently using. This is crucial because the configuration file you need to edit depends entirely on the shell.
    echo $SHELL
    Common outputs include /bin/zsh (default on macOS Catalina and later), /bin/bash, /bin/fish, or /opt/homebrew/bin/zsh. The steps below assume you are using the standard Zsh shell, which is the default for most modern Mac users.
  3. Locate the Configuration File: You need to edit the file where your shell looks for startup commands. For Zsh, this file is located in your home directory. Type the following command to navigate there and list the file (or create it if it doesn't exist).
    ls -la ~ | grep .zshrc
    If the output shows .zshrc (a hidden file starting with a dot), you are good to go. If it does not exist, you will create it in the next step.
  4. Edit the Configuration File: You will use a text editor to add the Homebrew paths to the file. If you are comfortable with the command line, you can use the built-in nano editor, which is user-friendly.
    nano ~/.zshrc
    This command opens the file in the editor. If the file is empty, it will appear blank. If it exists, you will see your current configuration settings. Do not worry if you cannot see your previous text clearly; the editor is designed to handle this.
  5. Add the Homebrew Initialization Line: You must add a single line of code to the end of the file. This line tells your shell where to look for Homebrew executables. Using the arrow keys on your keyboard, move your cursor to the very bottom of the screen. Type the following line exactly as shown, ensuring there are no typos:
    eval "$(/opt/homebrew/bin/brew shellenv)"
    Note: For Intel Macs (M1 chips are standard now, but Intel is still common), the path is often /usr/local/bin/brew. If the above command fails, try eval "$(/usr/local/bin/brew shellenv)" instead.
  6. Save and Exit the Editor: Once you have added the line, you need to save the file and close the editor. In Nano, press Ctrl + O (Control and O) to write the file, then press Enter to confirm. To exit, press Ctrl + X.
  7. Apply the Changes: The changes you made to the file won't take effect until you either restart your Terminal or manually reload the configuration. You can reload it instantly by typing the following command and pressing Enter:
    source ~/.zshrc
    This command reads the file you just edited and executes the new settings immediately.
  8. Test the Fix: Return to the command line and type the following command again to verify that Homebrew is now found.
    brew --version
    If the installation is correct, you will see the version number displayed. If you see an error, proceed to the Troubleshooting section.

Common Mistakes

  • Using the Wrong Shell Configuration: If you are using Zsh but are attempting to edit .bash_profile or .bashrc, the changes will not take effect. Always check your shell using the echo $SHELL command mentioned in Step 2 before editing any files.
  • Incorrect Path for Apple Silicon vs. Intel: Homebrew installs to different locations depending on your processor. On Apple Silicon Macs, it installs to /opt/homebrew. On Intel Macs, it installs to /usr/local. Using the wrong path in your configuration file will result in a command not found error for the shellenv command itself.
  • Typographical Errors: One missing parenthesis or a typo in the path string will break the command. Always double-check that you have typed the initialization line exactly as specified in the guide.
  • Not Reloading the File: Simply editing the file is not enough. You must run source ~/.zshrc or restart your Terminal for the new environment variables to be loaded into your current session.

Tips

  • Use a Better Editor: If you find Nano intimidating, you can install a command-line editor like VS Code or use a GUI text editor like TextEdit to edit the file. Just remember to save it as plain text and ensure the file ends with a newline character.
  • Check for Multiple Config Files: In some older or customized setups, your shell might load multiple configuration files (like .zprofile or .zlogin). If the .zshrc method fails, check if the Homebrew initialization line works in .zprofile instead.
  • Restart Your Terminal: Sometimes, simply closing the Terminal window and opening a new one is the easiest way to ensure all environment variables are correctly set.
  • Verify with type: If you are unsure if a command is found, type type brew. It will tell you where the command is located. If it says brew is /opt/homebrew/bin/brew, it is working.

Troubleshooting

If you have followed the steps and still see command not found: brew, try these solutions in order.

Restarting the Shell

Sometimes the environment variables get stuck or corrupted in the current session. The most effective first step is to restart your shell. Close the Terminal window completely and open a new one. Then, try the brew --version command again.

Checking File Permissions

If you attempted to edit the file and received a permission denied error, or if the file seems to be read-only, you may need to reset permissions. Open the Terminal and run the following command to ensure your user has write access to the configuration file:

chmod u+w ~/.zshrc
Then, try editing the file again.