Home / Blog / Tutorials / [Resolved] “zsh: command not found: brew” Error on Mac

Tutorials

"zsh: command not found: brew" Error

[Resolved] “zsh: command not found: brew” Error on Mac

Choose Your Language:

If you encounter the “zsh: command not found: brewerror on your Mac, it typically means that the Homebrew package manager is either not installed or not properly configured in your system’s PATH. Homebrew is an essential tool for many developers, allowing you to easily install and manage software packages. This guide will walk you through the steps to resolve the error and ensure Homebrew is working seamlessly on your Mac.

1 How to Resolve the “zsh: command not found: brew” Error

[Resolved] "zsh: command not found: brew" Error on Mac 2

To fix the “zsh: command not found: brew” error, follow these clear steps to ensure Homebrew is properly installed and configured.

1.1 Step 1: Confirm Homebrew Installation

First, let’s confirm that Homebrew is installed on your system. If you haven’t installed it yet, follow these steps to install it:

  1. Open your terminal.
  2. Run the following command to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Once the installation is complete, the terminal will display the next steps to take. These steps typically include adding Homebrew to your PATH.

1.2 Step 2: Add Homebrew to Your PATH

After installation, if you still see the “command not found” error, it’s likely that the Homebrew binary isn’t in your shell’s PATH. Here’s how to fix it:

  1. Open your .zshrc file. This file is located in your home directory (~):
nano ~/.zshrc
  1. Add the following line at the beginning of the file to include Homebrew’s path:
export PATH="/opt/homebrew/bin:$PATH"

Note: If you’re using an Apple Silicon Mac (M1, M2, etc.), Homebrew is installed in /opt/homebrew/ by default. If you’re on an Intel Mac, it might be installed in /usr/local/bin/.

  1. Save the file and exit nano by pressing Control + O (to save) and Control + X (to exit).
  2. Now, apply the changes by sourcing the .zshrc file:
source ~/.zshrc

1.3 Step 3: Verify the Installation

After sourcing the .zshrc file, you can check if Homebrew is accessible by running:

brew --version

If everything is set up correctly, this should return the installed version of Homebrew.

1.4 Step 4: Restart Your Terminal (Optional)

If you’re still encountering issues, try closing your terminal and opening it again. This can help apply changes that may not take effect immediately.

1.5 Troubleshooting

If you continue to see issues, here are some additional checks and steps:

  • Correct Path for Homebrew: Ensure you’re adding the correct path to .zshrc. If you’re unsure whether Homebrew is installed in /opt/homebrew or /usr/local/bin, you can locate Homebrew with:
which brew
  • Reinstall Homebrew: If none of the steps work, consider uninstalling and reinstalling Homebrew. To uninstall, run:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Then, re-run the installation command from Step 1.

By carefully following these steps, you should be able to resolve the “zsh: command not found: brew” error and get Homebrew running smoothly.

2 Conclusion

With these steps and troubleshooting tips, you now have the resources to address and resolve the “zsh: command not found: brew” error effectively. Ensuring that Homebrew is installed correctly and its path is properly configured will enable a seamless experience with this powerful package manager. By following the guide above, you can quickly get back to managing your software installations with confidence and ease.

Written by Harpreet Singh

Harpreet Singh is a highly skilled web developer with seven years of experience in the field. He specializes in HTML, CSS, JavaScript, UI/UX design, and PHP, making him a valuable asset to any web development team. With a passion for all things tech-related, Harpreet's expertise in creating visually stunning and functional websites is unmatched. He has honed his skills through years of practice and dedication to staying updated on the latest web development trends and techniques. As he writes for himself on kwebby.com, readers can expect insightful and informative content from someone who truly knows the ins and outs of web design. With Harpreet at the helm, you can be confident that your website will be in capable hands.