Mac OSX Tech

Fix Homebrew PATH on Apple Silicon macOS (M1, M2, M3)

If you see the warning ”/opt/homebrew/bin is not in your PATH” while using Homebrew on an Apple Silicon Mac (M1, M2, M3) or macOS Sequoia, it means your system cannot find Homebrew’s binaries. This can prevent you from running Homebrew commands like brew install.

By default, Homebrew installs in /opt/homebrew/bin on Apple Silicon Macs, but sometimes it doesn’t get appended to the system’s PATH variable especially in MacOS Sequoia using ZSH or Z Shell. In this guide, we’ll walk you through the steps to permanently add Homebrew to your PATH so you can use it without issues.

Fixing the Issue

The PATH environment variable tells macOS where to look for executable files when you enter a command. If /opt/homebrew/bin is missing from PATH, your system won’t recognize Homebrew commands like brew install.

Step 1: Check if Homebrew is Installed

Before making any changes, confirm whether Homebrew is installed by running:

brew --version

If it returns a version number, Homebrew is installed. If you see an error like command not found: brew, install Homebrew by running:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Follow the on-screen instructions to complete the installation.

Step 2: Check Your Current PATH

To see if /opt/homebrew/bin is in your PATH, run:

echo $PATH

If you don’t see /opt/homebrew/bin, proceed with the next step as you need to add /opt/homebrew/bin to your PATH. Here’s how:

Step 3: Open Terminal

Launch Terminal on your Mac.

Step 4: Add Homebrew to Your PATH

Run the following command to add it for the current session:

export PATH="/opt/homebrew/bin:$PATH"

This will temporarily fix the issue, but it will reset whenever you restart your terminal.

Step 5: Permanently Add Homebrew to the PATH

To make it permanent, add the following line to your shell configuration file:

• If you use zsh (default on macOS):

echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

• If you use bash:

echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

Step 6: Verify Homebrew Works

Run:

brew doctor

If Homebrew is properly set up, it should return something like:

“Your system is ready to brew.”

By following these steps, you have successfully added Homebrew to your system’s PATH. Now, you can run brew commands without encountering any error.

Homebrew Still Isn’t Recognized? Try These Fixes:

If Homebrew commands still don’t work, try the following:

1- Restart Your Terminal

Close and reopen Terminal to apply changes.

2- Check Your Shell

Run echo $SHELL. If it returns /bin/zsh, you should edit ~/.zshrc. If it returns /bin/bash, edit ~/.bash_profile.

3- Manually Add Homebrew to Shell Profile

If echo $PATH doesn’t show /opt/homebrew/bin, manually edit your shell configuration file:

nano ~/.zshrc

Add this line at the bottom:

export PATH="/opt/homebrew/bin:$PATH"

Press Control + X, then Y, then Enter to save.

4- Ensure Homebrew’s Folders Have Correct Permissions

sudo chown -R $(whoami) /opt/homebrew

This makes sure you have the right permissions to use Homebrew.

5- Reinstall Homebrew

If nothing else works, uninstall and reinstall Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

Then reinstall it using the command from Step 1.