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

bash brew command not found

Homebrew or most commonly known as brew is the quite popular package manager when it comes to macOS the (Unix) 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, 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 brew is installed?

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

% which -s brew 
brew not found

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

% which -s brew 
brew not found

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

bash-3.2$ which brew

How to fix brew command not found error?

If 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 asked for 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 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 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 Mac's 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

Have Questions? Post them here!

Topics Coverage:

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.

Follow Us: GitHub | Facebook | Twitter | Instagram