How to Fix ‘zsh: command not found’ in macOS Terminal

Executing a utility, script, or development tool in the macOS Terminal only to be greeted with the error message “zsh: command not found” is one of the most common stumbling blocks encountered by developers, system administrators, and everyday Mac power users. Ever since Apple transitioned macOS from Bash to the Z shell (Zsh) as the default login shell starting with macOS Catalina, command invocation rules and environment initialisation workflows have changed. When you type a command into your terminal prompt, Zsh consults a predefined list of filesystem directories stored inside the $PATH environment variable. If the directory containing the requested executable is absent from your path, if your shell configuration profile (~/.zshrc) contains syntax errors, or if you recently installed a utility through Homebrew on Apple Silicon without configuring the correct architecture prefixes, Zsh cannot locate the binary. This technical guide outlines how shell path resolution works on macOS and provides definitive methods to fix the error.

What Causes ‘zsh: command not found’ on macOS?

Understanding how the Z shell searches for binaries simplifies troubleshooting. The error occurs when:

  • Missing Binary Directory in $PATH: The binary exists on your disk, but its containing folder (such as /usr/local/bin, /opt/homebrew/bin, or language-specific paths like ~/.nvm or ~/.cargo/bin) is not included in the active $PATH string.
  • Apple Silicon (M1/M2/M3/M4) Architecture Differences: On Intel Macs, Homebrew installs binaries into /usr/local/bin. On Apple Silicon Macs, Homebrew installs binaries into /opt/homebrew/bin to avoid binary architecture collisions. Without the proper shell configuration, Zsh cannot find Homebrew packages on Apple Silicon.
  • Typographical Errors: A misspelled command name or incorrect letter casing (remembering that UNIX commands are strictly case-sensitive).
  • Corrupted or Overwritten ~/.zshrc: An improperly formatted export statement (e.g. typing export PATH=/custom/path instead of appending export PATH="$PATH:/custom/path") completely wipes out standard system paths like /usr/bin and /bin.
  • Uninstalled Tool: The software package was never installed, was removed during an operating system update, or was wiped during an uninstallation routine.

Method 1: Verify the Current $PATH Environment Variable

Before modifying configuration files, inspect the current directories that Zsh is scanning for executables.

  1. Open Terminal from your Applications > Utilities folder or via Spotlight (Command + Space).
  2. Run the following command to print your active path:
    echo $PATH
  3. A healthy macOS path should at minimum contain:
    /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
  4. If your output is blank or contains only a single custom directory, your $PATH variable was accidentally overwritten by a script or configuration entry.

Method 2: Locate the Binary on Your Disk

Verify whether the command or executable actually exists on your Mac’s filesystem.

  1. Use the which or where command to check for existing alias mappings:
    which python3
  2. If which returns no output, use find to locate the binary manually across common installation directories:
    find /opt/homebrew/bin /usr/local/bin /usr/bin -name "your_command" 2>/dev/null
    (Replace your_command with the tool you are attempting to run, such as git, node, or brew).
  3. If the binary is found (for example, at /opt/homebrew/bin/brew), you simply need to add its parent folder to your shell path.

Method 3: Configure Homebrew Path for Apple Silicon and Intel

If commands installed via Homebrew trigger the “command not found” error, your shell environment has not evaluated Homebrew’s shellenv script.

  1. Open your Zsh profile for editing using the built-in Nano editor:
    nano ~/.zshrc
  2. Scroll to the bottom of the file and add the universal Homebrew initialization snippet:
    if [[ -f /opt/homebrew/bin/brew ]]; then
        eval "$(/opt/homebrew/bin/brew shellenv)"
    elif [[ -f /usr/local/bin/brew ]]; then
        eval "$(/usr/local/bin/brew shellenv)"
    fi
  3. This snippet dynamically detects whether your Mac is Apple Silicon (/opt/homebrew) or Intel (/usr/local) and configures the environment accordingly.
  4. Press Ctrl + O followed by Enter to save the file, then press Ctrl + X to exit Nano.
  5. Reload your shell configuration immediately:
    source ~/.zshrc

Method 4: Restore Default macOS System Paths in ~/.zshrc

If standard operating system utilities like ls, grep, sudo, or nano are also reporting “command not found”, your profile has broken the default path structure.

  1. Open your ~/.zshrc file using the full absolute path to the Nano editor:
    /usr/bin/nano ~/.zshrc
  2. Look for any line starting with export PATH=.
  3. Ensure that your path declarations properly append existing paths rather than overwriting them. Add the following safe declaration at the very top of the file:
    export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
  4. Save the file with Ctrl + O and exit with Ctrl + X.
  5. Apply the updated path:
    source ~/.zshrc
  6. Verify that standard system commands work as expected.

Method 5: Rehash the Zsh Command Completion Cache

Zsh maintains an internal hash table of binary locations in memory. If you installed a package in one terminal tab while another was already open, the existing session may fail to recognize the newly created binary.

  1. Run the rehash command inside your active terminal window:
    rehash
  2. Try executing your command again.
  3. If the error persists, close the Terminal completely by pressing Command + Q and launch a fresh session.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.