Skip to main content

Fixing 'command not found: brew' on Apple Silicon Macs: Configuring Your PATH

 You run the official Homebrew installation script, wait for the download to complete, and see the "Installation successful!" message. You type brew install node, press enter, and immediately hit a wall: zsh: command not found: brew.

This is one of the most common friction points for developers setting up a new M-series machine. The system completely fails to recognize Homebrew, despite the binaries existing on your solid-state drive. Resolving the command not found brew macOS error requires a straightforward but manual adjustment to your shell configuration file.

Why Apple Silicon Breaks the Default Homebrew Path

To understand the fix, you must understand how Unix-based systems locate executable files. When you type a command like brew, your shell (Zsh, by default on modern macOS) scans a specific list of directories defined by the $PATH environment variable.

Historically, on Intel-based Macs, Homebrew installed itself into the /usr/local/bin directory. Because macOS includes /usr/local/bin in the default $PATH out of the box, the brew command worked immediately without any post-installation configuration.

With the transition to ARM architecture (M1, M2, M3, and M4 chips), the Homebrew maintainers made a strategic architectural change. They relocated the installation directory to /opt/homebrew. This shift cleanly separates native Apple Silicon binaries from emulated x86_64 binaries running via Rosetta 2, preventing system conflicts and cross-architecture contamination.

However, macOS does not include /opt/homebrew/bin in its default $PATH. Consequently, the shell has no idea where to find the executable, resulting in the Apple silicon homebrew path disconnect.

The Fix: Appending Homebrew to Your PATH

To permanently resolve this issue, you must explicitly ensure your system checks the opt homebrew bin path before falling back to default system directories. This requires updating your Zsh configuration files.

Execute the following commands in your terminal. This appends the necessary Homebrew environment configuration to your .zprofile (which loads on login) and evaluates it immediately for your current session.

# 1. Add the Homebrew shell environment configuration to your .zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile

# 2. Apply the changes immediately to your current terminal session
eval "$(/opt/homebrew/bin/brew shellenv)"

Verify the fix is successful by checking the Homebrew version and mapping its system location:

brew --version
# Expected output: Homebrew 4.x.x

which brew
# Expected output: /opt/homebrew/bin/brew

Deep Dive: How the Shellenv Command Works

Many developers bypass the official instructions and manually edit their profile to append export PATH="/opt/homebrew/bin:$PATH". While this works for basic command execution, it is incomplete and inherently brittle.

Using the brew shellenv method is the technically rigorous approach. When you execute /opt/homebrew/bin/brew shellenv, the Homebrew executable programmatically generates a specific set of environment variables based on your system architecture.

Run the command directly to see what it does under the hood:

/opt/homebrew/bin/brew shellenv

You will see output similar to this:

export HOMEBREW_PREFIX="/opt/homebrew"
export HOMEBREW_CELLAR="/opt/homebrew/Cellar"
export HOMEBREW_REPOSITORY="/opt/homebrew"
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}"
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:"
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}"

The eval command takes this multiline string output and executes it directly within the context of your current shell. This not only sets the correct PATH for the brew command but also ensures that system manuals (MANPATH) and compiler info paths (INFOPATH) correctly point to your Homebrew-installed packages. Manual configuration almost always misses these supplementary paths.

Common Pitfalls and Edge Cases

1. The Difference Between .zshrc and .zprofile

When searching for a zshrc configure homebrew Mac solution, developers often confuse .zshrc and .zprofile.

By default, macOS terminal windows open as "login shells." Zsh reads the .zprofile file during login shell initialization. Therefore, placing environment variable exports in .zprofile ensures they are set early in the shell lifecycle and properly inherited by subshells.

Placing the eval command in .zshrc will also technically work, but .zshrc is strictly intended for interactive shell configurations (like aliases, prompt themes, and syntax highlighting) rather than global path and environment definitions. Sticking to .zprofile aligns with POSIX standards.

2. Legacy Bash Users

If you have manually reverted your macOS shell from Zsh back to Bash, updating .zprofile or .zshrc will have no effect. You must apply the configuration to your .bash_profile.

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"

3. Syntax Errors in Configuration Files

If you accidentally overwrite your configuration file instead of appending to it (using > instead of >>), you risk destroying existing path configurations for tools like NVM or Pyenv. Always verify the file contents if things behave unexpectedly:

cat ~/.zprofile

Ensure the line reads exactly eval "$(/opt/homebrew/bin/brew shellenv)" with the correct nested double and single quotes. If the internal command executes before the string is written, your profile will contain static exports rather than the dynamic eval command, which can break during future Homebrew updates.

Conclusion

The transition to Apple Silicon brought massive performance gains to macOS development environments, but it mandated strict architectural boundaries like the isolated /opt/homebrew directory. By correctly utilizing the brew shellenv evaluation in your profile configuration, you ensure your shell maintains a clean, robust, and accurate mapping to all natively compiled ARM binaries.