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
brewstill 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:
/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.
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.
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:
brew --versionA 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:
xcode-select --installFollow 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:
# 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:
source ~/.zprofileThen 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.
brew doctorIt 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.
Comments (0)
Sign in to comment
Report