[Fix] brew: command not found Mac or Linux Terminal Error


Homebrew or most commonly known as brew is a quite popular package manager when it comes to macOS the Operating System for MacBooks and Mac Computers, nevertheless it is also quite famous with Linux Operating Systems as well.


Most common brew error messages

    ZSH Shell

    % zsh: command not found: brew

    Bash Shell

    $ bash: brew: command not found

    Sh Shell

    $ sh: brew: command not found


Why brew: command not found error?

    brew command not found error

    The most common reason for the message "brew: command not found" is either you do not have Homebrew installed on your device, or you have not set the path for it.

    When you run the brew command to install a package, the terminal looks for the brew binary in certain system paths and profile files to locate brew, if it is not found, you get the brew not found error.


How to find out if the brew is installed?

    As we discussed, one of the reasons could be that Brew is installed on your device but it's not set in the $PATH environment variable. You can find out if the brew binary is available or not by running the which command in a terminal,

    % which -s brew 
    brew not found

    If you get brew not found then brew is missing on your device or the path is not set.

    % which -s brew 
    brew not found

    If the brew is installed and the path is set you will get the output as where the brew is installed,

    Example:
    bash-3.2$ which brew
    /opt/homebrew/bin/brew


    How to fix the brew command not found an error?

    If the brew is not installed on your macOS or Linux device, you would first need to get it installed.


Installing Homebrew on macOS/Linux

  1. Open Terminal/Linux shell prompt the command line application on your device,
  2. Now visit the brew website (https://brew.sh) and look for the command with install.sh,
    $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Note that you should have curl command package installed as a prerequisite.
  4. Copy the bash command and run it on any shell: zsh, bash, or sh,
  5. On macOS you will be asked for a password and Xcode Command Line Tools will be installed as well which may take a while to download,
  6. Once the installation is complete you should see a Next Step with the below details based on which shell you are in,
    ==> Next steps:
        - Run these three commands in your terminal to add Homebrew to your PATH:
        echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/code2care/.zprofile
        echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/code2care/.zprofile
        eval "$(/opt/homebrew/bin/brew shellenv)"

    The above commands are specific to my user, device, and shell, do not copy these.

  7. Check if the brew command is now available or not using the --version option,
    % brew --version
    Homebrew 3.6.6
    Homebrew/homebrew-core (git revision 9723dbb3bd5; last commit 2022-10-20)

Setting PATH for brew using command line

    For Apple Silicon based M1/M2 Mac

    For Macbook's running on Apple ARM based M1/M2 chip brew is installed at location /opt/homebrew/bin

    ZSH Shell:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/your-user/.zprofile
    Bash Shell:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/your-user/.zprofile


    For Intel based Mac

    For Macs running on Intel-based chip brew is installed at location /user/local/bin

    ZSH Shell:
    echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/your-user/.zprofile
    Bash Shell:
    echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/your-user/.zprofile


    For Linux

    ZSH Shell:
    echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/your-user/.zprofile
    Bash Shell:
    echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/your-user/.zprofile
bash brew command not found

This is not an AI-generated article but is demonstrated by a human on an M1 Mac running macOS Sonoma 14.0.

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap