It’s Murphy’s Law. If I’m going to have a problem with a software package, it’s when I’m in a hurry. Sometimes, it’s an easy fix; other times, it takes hours searching the web to find a solution. If you’ve encountered Homebrew’s error message “Command Not Found,” I sympathize. It’s rather ironic that an organization that markets Homebrew (or brew) as the missing software package manager is missing something.
First, brew developers restrict support to the last three versions of Mac’s operating systems. When a new version is released, the team drops support for the oldest operating system. Although this approach ensures the development teams focus on the most current releases, it also means you need to upgrade if you’re not on a supported release. If you’re current, then here are my suggestions for fixing the “Command Not Found” error message.
Command Not Found
After installing the software, you may receive an error message of “Command Not Found” when you try to run the application. The message is a common error that appears when the executable binary is not in a directory listed under PATH.
PATH is an environment variable that stores system-wide values for accessing resources. It identifies the directories to search for executable files. If the directory is not listed, the command cannot execute.
Check the Environment Variable
I suggest checking to see if the environment variable is correct using the following command:
/usr/bin/open ~/.bash_profile
If the variable is not present, I suggest using one of the following methods to fix the error.
Add to PATH
Although the installer should automatically add brew to PATH, sometimes the process fails or is interrupted. If that happens, the most straightforward way I’ve found is to add brew to Path.
- Run the following command to add the directory.echo ‘export PATH=”/usr/local/bin:$PATH”‘ >> ~/.bash_profileIf operating on an M1 processor, replace the command with: export Path=$PATH:/opt/homebrew/bin
- Activate the changes using the following command:source .bash_profile
- Check that the variable is present using /usr/bin/open ~/.bash_profile
Reinstall Homebrew
Sometimes, reinstalling is the better solution if the software does not operate as expected. In those instances, you must first uninstall the instance.
Uninstall Homebrew
The best way to uninstall Homebrew is to use the official script available through Github.
1. Open a terminal window.
2. Copy the following command to the window.
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)”
3. Run the script.
You can find the command in the Homebrew official Github repository.
Install Homebrew
Installing Homebrew is as simple as copying a command from the website.
1. Copy the install command from the Homebrew’s official website.
2. Paste the command into Terminal window.
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
The command references bash rather than ruby because the installer has been rewritten in Bash for better compatibility.
Apple M1 Devices
Homebrew installs in the /opt/homebrew folder instead of the /usr/local/homebrew folder on Apple’s M1devices. As a result, it does not appear in $PATH. Use the following two commands to add Homebrew to a .zprofile file.
echo ‘eval “$(/opt/homebrew/bin/brew shellenv)”‘ >> /.zprofile
eval “$(/opt/homebrew/bin/brew shellenv)”
The first command adds brew to the shell startup file and the second activates the changes immediately.
Install XCode
In the latest installation scripts, Homebrew can install XCode command line tools if they are not installed. Since the tools are needed to ensure that brew runs, press Return when prompted to install the tools. Alternatively, you can install XCode Command Line tools using the following process.
1. Open Terminal.
2. Enter xcode-select –install.
3. Select Install to begin the installation process.
4. Open XCode after the installation is complete.
5. Select Preferences>Location.
6. Select XCode version under Command Line Tools.
7. Run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
If using a Mac M1, enter the following command; then close and reopen Terminal.
echo "export PATH=/opt/homebrew/bin:$PATH" >> .zshrc
More Information
Homebrew has an extensive set of documentation if you’re looking for more information. But, nothing beats experience. I’d like to hear what obstacles you have had installing brew. Did XCode install easily within the brew installation? Were there issues using the XCode tools or Homebrew? What are your thoughts on brew as a software package manager?