Homebrew is a free and open-source software package management system for Apple’s macOS and Linux operating systems, allowing users to easily install software.
While not being pre-installed on every macOS device, it’s a third-party package manager that administrators never knew they needed until they tried it out
The lightweight package manager is based on Ruby and uses GitHub to fetch installs, update apps, and add repositories where developers can add applications to be managed through command-line interfaces.
When users are attempting to install Homebrew, they can encounter an error message that says "brew: command not found". This article is going to show you a few possible fix to the error.
Why "brew : command not found"?
If you receive the "brew : command not found" error, the brew
executable binary isn’t in one of the directories listed in your PATH
environment variable.
Environment variables are system variables that are accessible by all processes and users operating under the Operating System (OS), such as Windows, macOS, and Linux. For example, environment variables can be used to store values system-wide.
PATH
is the most common environment variable. It stores a list of directories that are searched for executable files.
Reinstall Homebrew
Often when a software does not work as intended, reinstalling it from scratch may be the way to go.
In order to properly uninstall Homebrew, we have to use its official script by opening up a Terminal window and run.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
The command above is taken from Homebrew official Github repo
Once the uninstall process has completed, head over to Homebrew official website and carefully copy and paste the one-line installation command and paste it into Terminal.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
If you’re wondering why the command includes /bin/bash
instead of ruby
, the answer is Homebrew installer has been rewritten in Bash recently to ensure better compatibility.
Add brew to PATH
The Homebrew installer does automatically add brew
to PATH
, but sometimes, the process may have been interrupted and cause "brew: command not found".
Therefore, if you do not have the brew
environment variable configured, the following steps must be taken:
-
You should run the following command to set up your Mac’s environment variable
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
Depending on where
brew
was installed you might have to replaceexport PATH="/usr/local/bin:$PATH"
withexport PATH=$PATH:/opt/homebrew/bin
-
Now we need to activate the changes. Type this command to activate and try
drew doctor
again:source .bash_profile
Alternatively, if you already configured the environment variable, you can use this command to see if the configuration is correct:
/usr/bin/open ~/.bash_profile
Homebrew on M1/Apple Silicon devices
If you’re using a new Mac which is powered by Apple M1 processor, Homebrew installer may show you the instruction to add brew
to zsh
configuration file, named .zprofile
.
The reason for that is ARM version of the Homebrew must be installed in /opt/homebrew
instead of the usual /usr/local/homebrew
.
[email protected] ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
...
==> Next steps:
- Add Homebrew to your PATH in /Users/668/.zprofile:
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/668/.zprofile
eval $(/opt/homebrew/bin/brew shellenv)
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
[email protected] ~ % brew install --cask google-chrome
zsh: command not found: brew
You can solve "brew: command not found" on your Mac M1 by carefully copying and running each line in the instructions. In my case, it is:
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/668/.zprofile
eval $(/opt/homebrew/bin/brew shellenv)
The first line adds the brew shellenv
line to your shell startup file, while the second actually changes your current shell session environment so that the changes take effect immediately.
You may wish to add brew
to your .zshrc
, too
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> $HOME/.zshrc
Install XCode
Users online have reported that if you didn’t have XCode on your system, Homebrew may not work. Follow the steps below to install XCode on your macOS.
Step 1 : Check if you have already installed Xcode by running the following command in your terminal
/usr/bin/xcodebuild -version
If it prints something like below, XCode is already installed.
Xcode 12.3 Build version 12C33
Step 2 : Open XCode and select Preferences > Location. Under Command Line Tools, select your XCode version.
Step 3 : Open Terminal and run the following command
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 4 (Optional): If you’re using a Mac M1, run the following command, then close terminal and reopen the terminal again
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
We hope that by the end of the article, you now fixed the "brew: command not found" error message on your macOS device.
If all the methods above does not work, you can always raise an issue at Homebrew Github repository for help from the original developers.
This was super helpful and fix my issue of “brew command not found”
Thanks so much guys!
Very helpful article. I managed to fix my issue on my M1