Brew command not found after install
In this article we will discuss the error of brew commands not found on every Operating system and their possible reasons as well as solutions.
What is HomeBrew?
Homebrew is a package manager for macOS which allows you to install free and open-source software packages using Brew terminal. You’ll use Homebrew to install developer tools like Python, Ruby, Node.js, and more. It will allow you to download third-party apps in Mac which are usually not available in Mac. HomeBrew is now also compatible with Windows by WSL and Linux.
Brew command not found
After installing Homebrew on your computer if you get a message “Command not found” indicates that the brew binary isn’t on one of the directories listed in your PATH environment variable. To check what your path is currently, run echo $PATH. By default, brew installs to the directory /usr/local/bin. To remove the error you have to set the path permanently to the right directory, you need to edit your ~/.bashrc file to contain the line. Simply export PATH=”/usr/local/bin:$PATH after exporting you need to config the environment. Use the following command below to open the file to check if the environment configuration is correct:
/usr/bin/open ~/.bash_profile after saving, close the terminal, and do not forget to activate your changes. Use source .bash_profile
For Macbook M1
If you are using Macbook M1 the command will have little changes. To remove the command not found error on Macbook M1, use echo $PATH
Check X code
Check if the X code is installed in the program or not. Xcode is a complete developer toolset for creating apps for Mac, iPhone, iPad, Apple Watch, and Apple TV. Xcode brings user interface design, coding, testing, debugging, and submitting to the App Store into a unified workflow.
Install X code
You won’t need Xcode to use Homebrew, but some of the software and components you’ll want to install will rely on Xcode’s Command Line Tools package.
Execute the command line in the Terminal to download and install these components:
You will see a prompt to allow you to start the installation and then be prompted again to accept a software license after accepting the tools will download and install automatically.
Why do you need an X code?
Xcode is a macOS application made by Apple for app development. It is the only officially supported way to develop iOS and other Apple Operating System apps. You can think of Xcode as your crucial element for app development. You use Xcode to write your code and build your user interfaces.
If this doesn’t work, use the command on your profile nano ~/.profile
After this add these commands : export PATH=”$HOME/.linuxbrew/bin:$PATH”
Commands if Distribution is in Ruby
If none of the suggestions above worked. I changed directories cd ~/tmp and type this command:
ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)” . Before changing directories this command will work if you were working in a directory that is a Git repository. The error was coming because it was interfering with the ruby and Git commands in the Brew install script.
ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)”
then install https://github.com/robbyrussell/oh-my-zsh.
When these commands run a pico editor pico .zshrc and past those commands use:
After running the commands make sure to use brew doctor
Use this command line: ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/linuxbrew/go/install)
You can use this:
ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”
to install homebrew again and start over.
How to install, upgrade and remove a package
The tree command lists a complete graphical directory tree and is available via Homebrew.
You can Install the tree with the brew install command:
brew install tree
Homebrew will immediately update its list of packages and then download and install the tree command simultaneously. The installation of the package will look like this:
==> Downloading https://homebrew.bintray.com/bottles/tree-1.8.0.catalina.bottle.tar.gz
==> Pouring tree-1.8.0.catalina.bottle.tar.gz
🍺 /usr/local/Cellar/tree/1.8.0: 8 files, 117.2KB
Homebrew will install the files to /usr/local storage by default, it is done to prevent any interference with future macOS updates. Verify that tree is installed by displaying the command’s location with the which command repository:
The respective output indicates that location of the tree is located in /usr/local/bin:
The output will look something like this:
Run the tree command to see the current version:
The version prints to the screen, indicating it’s installed will look like this:
tree v1.8.0 (c) 1996 – 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
If the tree package is running an old version and you want to upgrade an existing package. Simply use the brew upgrade command, followed by the package name:
brew upgrade tree
You can run brew upgrade without any additional arguments and will automatically upgrade all programs and packages Homebrew currently manages.
When you install a new version, Homebrew keeps the older version on the disk. After frequent updates, the older versions might have taken some good amount of space and you want to reclaim disk space by removing these older versions. Run brew cleanup command line to remove all old versions of your Homebrew-managed software.
Removing a package
To remove a package you no longer want to use, use brew uninstall. To uninstall the tree command, execute this command:
brew uninstall tree
The output shows that the package was removed:
Uninstalling /usr/local/Cellar/tree/1.8.0… (8 files, 117.2KB)
You can use Homebrew to install desktop applications too.
If you no longer need Homebrew, you can use its uninstall script.
Download the uninstall script with curl:
curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh
As always, review the contents of the script with the less command to verify the script’s contents:
Once you’ve verified the script, execute the script with the –help flag to see the various options you can use:
bash uninstall.sh –help
The options displayed on the screen will look like this:
Usage: uninstall.sh [options]
-p, –path=PATH Sets Homebrew prefix. Defaults to /usr/local.
Skips removal of HOMEBREW_CACHE and HOMEBREW_LOGS.
-f, –force Uninstall without prompting.
-q, –quiet Suppress all output.
-d, –dry-run Simulate uninstall but don’t remove anything.
-h, –help Display this message.
Use the -d flag to see what the script will do:
bash uninstall.sh -d
The script will list everything it will delete:
Warning: This script would remove:
/usr/local/bin/brew -> /usr/local/bin/brew
==> Removing Homebrew installation…
When you’re ready to remove everything, execute the script without any flags:
This removes Homebrew and any programs you’ve installed in your disk space. If you use the right command line on the correct distribution, it will remove the previous versions by running this command line.
In this article, we discussed the basic knowledge of Homebrew and its functions. We discussed the “command not found error” and how to solve it with different methods. First, you need to check if you have installed the X code which helps in developing software and plays a major role in app development. There are different commands for different distributions. You should use the correct command line according to your distribution. If you are using Ruby, then there are different command lines as well as for Linux.
Remember you cannot download Homebrew directly in Windows. You need a Windows Subsystem Linux (WSL). It is a subsystem that can run Homebrew, it works like a virtual machine but it is not. Hope this article helps you and you can solve the error after reading this article.