devcrea

How to Fix "zsh: command not found: brew" on macOS (Intel & Apple Silicon)

Run the brew shellenv fix for Apple Silicon or Intel, resolve Rosetta conflicts, and recover Homebrew after a macOS update. Includes diagnostic commands.

// The short answer

The zsh: command not found: brew error means Homebrew is either not installed or its binary directory is missing from PATH. Check /opt/homebrew/bin/brew --version on Apple Silicon and /usr/local/bin/brew --version on Intel; once the binary exists, add the matching directory to your shell configuration, reload it, and verify with brew --version.

Full walkthrough, edge cases and why it works
In this guide · 6 sections
  1. 01The 30-Second Diagnostic: Why is Homebrew Missing?
  2. 02Fix 1: Add Homebrew to Your PATH (The Official Way)
  3. 03Fix 2: Resolve the Rosetta 2 Terminal Conflict
  4. 04Fix 3: Restore Homebrew After a macOS Major Update
  5. 05Fix 4: NVM and PATH Shadowing Conflicts
  6. 06Still Failing? Run brew doctor

The zsh: command not found: brew error triggers when your terminal shell cannot locate the Homebrew binary in its execution path, often after a fresh installation or a major macOS system update. Resolving this requires mapping the correct directory to your shell configuration file based on your specific Mac architecture.

Target OS: macOS

Apple Silicon Path: /opt/homebrew/bin/brew

Intel Path: /usr/local/bin/brew

Instant Diagnostic Command: /opt/homebrew/bin/brew --version

The 30-Second Diagnostic: Why is Homebrew Missing?

Running the instant diagnostic command above reveals your exact situation:

  • Version number printed → Homebrew is installed but missing from your shell environment. Skip straight to Fix 1.
  • no file or directory → Homebrew is not installed at all. Run the installation script below first, then return to Fix 1.
  • Command runs but brew still fails after PATH fix → Check Fix 2 (Rosetta) or Fix 3 (macOS update).

If the terminal returns no file or directory, your system lacks the Homebrew files entirely. Run the official installation script first:

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

After the installation finishes, read the terminal output carefully. The Homebrew installer prints a Next steps section with the exact PATH commands for your architecture. Copy and paste those commands before doing anything else. Most users miss this step entirely, which is why the error persists even after a successful install.

Fix 1: Add Homebrew to Your PATH (The Official Way)

Many online tutorials suggest modifying your PATH variables manually. This approach is fragile. Using the native brew shellenv command builds the correct environment variables dynamically and prevents syntax errors.

For Apple Silicon Macs (M1/M2/M3/M4)

Apple Silicon architecture stores Homebrew files in the /opt/homebrew directory. Open your terminal and run these two commands exactly as written.

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

For Intel Macs

Older Intel processors use a different default directory structure. Your Homebrew installation lives in /usr/local/bin.

bash2 lines
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/usr/local/bin/brew shellenv)"

Why .zprofile is Better Than .zshrc

Your .zprofile file runs only once during the macOS login process. The .zshrc file executes every single time you open a new terminal window or tab.

Placing environment variables in your login shell optimizes terminal startup speed. It prevents redundant script executions that slow down your development environment. Homebrew's own documentation recommends .zprofile for this reason.

After running the commands above, verify the fix:

bash1 line
brew --version

A version number means the fix worked.

Fix 2: Resolve the Rosetta 2 Terminal Conflict

Apple Silicon users face a unique architectural conflict that causes this specific command error. Opening your Terminal application through Rosetta runs it in an x86_64 context.

This legacy context completely ignores the native /opt/homebrew directory. You can confirm this is your situation by running uname -m in the terminal. If it returns x86_64 instead of arm64, you are running in Rosetta mode.

Navigate to your Applications folder and open the Utilities folder. Right-click on your Terminal application and select Get Info. Ensure the Open using Rosetta checkbox remains unchecked. Relaunch Terminal after making this change.

Fix 3: Restore Homebrew After a macOS Major Update

Upgrading to a new macOS version often wipes out your system developer tools. Homebrew relies entirely on the Xcode Command Line Tools to function properly.

If the brew command disappears immediately after a system update, run this in your terminal:

bash1 line
xcode-select --install

Follow the onscreen prompt to reinstall the developer tools, wait for the download to finish, and restart your terminal application. If brew still fails after reinstalling the tools, run the Homebrew installation script again. The installer is safe to run on an existing installation and will repair broken configurations.

Fix 4: NVM and PATH Shadowing Conflicts

Node Version Manager (NVM) configurations sometimes override system paths aggressively. If your shell configuration file loads NVM after Homebrew, it might shadow the brew command completely. The same issue applies to Conda environments, which inject their own PATH entries at startup.

Open your ~/.zprofile or ~/.zshrc and check the order of entries. The Homebrew eval line should sit at the top of the file, before any NVM or Conda initialization blocks. Reverse the order if needed:

bash6 lines
# Homebrew first
eval "$(/opt/homebrew/bin/brew shellenv)"

# NVM after
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

After reordering, reload your configuration:

bash1 line
source ~/.zprofile

Then verify brew responds correctly with brew --version.

Still Failing? Run brew doctor

Homebrew has a built-in self-diagnostic tool. Even if the PATH is now correct, other issues like incorrect permissions or broken symlinks can cause problems.

bash1 line
brew doctor

It scans your system and prints specific instructions for each problem it finds. Fix whatever it reports before trying to install packages. Most post-upgrade issues show up here.

Once Homebrew is working, use brew list to check what else needs attention. Tools like Node.js and pip may also need updates after a major system repair.

Quick answers

Frequently asked questions

Why do I get zsh: command not found: brew after installing Homebrew?

The installer completed but did not update your shell's PATH. Run `eval "$(/opt/homebrew/bin/brew shellenv)"` (Apple Silicon) or `eval "$(/usr/local/bin/brew shellenv)"` (Intel) to fix it immediately, then add the same line to your ~/.zprofile to make it permanent.

What is the difference between .zshrc and .zprofile for Homebrew?

.zprofile runs once at login and is where Homebrew recommends placing its PATH configuration. .zshrc runs every time you open a new terminal tab. Both work, but .zprofile is faster and avoids redundant script execution.

What does brew shellenv do?

It outputs the correct environment variables for your Homebrew installation, including the PATH, based on your Mac architecture. Using eval with this command is more reliable than manually typing export PATH because it automatically adjusts for Apple Silicon versus Intel paths.

Why is brew not found on my M1/M2/M3 Mac?

Apple Silicon Macs install Homebrew at /opt/homebrew, which is not in the default PATH. You need to add `eval "$(/opt/homebrew/bin/brew shellenv)"` to your ~/.zprofile. Also check that Terminal is not running in Rosetta mode by running `uname -m` and ensuring it returns arm64.

How do I fix brew command not found after a macOS update?

macOS updates often remove Xcode Command Line Tools, which Homebrew depends on. Run `xcode-select --install` to reinstall them. If brew still fails, run the Homebrew installation script again as it safely repairs an existing installation.

Can NVM or Conda break my Homebrew PATH?

Yes. If NVM or Conda initializes after Homebrew in your config file, it can override the PATH and shadow the brew command. Move the Homebrew eval line to the top of your ~/.zprofile or ~/.zshrc, before any NVM or Conda blocks.

How do I check if Homebrew is actually installed?

Run `/opt/homebrew/bin/brew --version` (Apple Silicon) or `/usr/local/bin/brew --version` (Intel) using the full path. If this returns a version number, Homebrew is installed but missing from your PATH. If it returns an error, Homebrew needs to be installed.

What does brew doctor do?

It scans your system for configuration problems including incorrect permissions, broken symlinks, and missing dependencies. Run it after fixing the PATH issue to catch any remaining problems before installing packages.

Something wrong or out of date?

Tools change fast. Tell the editor what no longer works.