Zsh: command not found: brew is an error that often occurs while setting up git homebrew on a new device. It often signals that git was not added to the PATH variable during installation, therefore, the shell could not locate the homebrew executable.
3 steps to Fix Zsh: Command Not Found: Brew Solved
- Confirm git is installed:
git --version - Add homebrew to the PATH variable: You can do so by running
export PATH="/opt/homebrew/bin:$PATH"in your terminal, followed byecho $PATH. - Run brew install again: Enter brew install git in your terminal and wait for it to download.
The error happened to me my first time setting up git on my Macbook a few years ago. It happened again a few years later, except I didn’t take note of how I fixed it. So, I am writing this short article for myself and anyone else who may face this issue.
How to Fix Zsh: Command Not Found: Brew
First, go to the git download page, and download the appropriate version according to your device. Since I am using a Macbook, I downloaded the version for macOS.
To download, first install homebrew by running the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
According to the documentation, after installing homebrew in your terminal, run:
brew install git
This is when it throws an error:
zsh: command not found: brew
1. Confirm Git Is Installed
The first step is to confirm git is installed by running:
git --version
Running this command confirms that git was properly installed:
git version 2.39.3 (Apple Git-146)
However, if you receive an error, it’ll become clear that homebrew was not added to the PATH variable during installation, therefore, shell could not locate the homebrew executable.
2. Add Homebrew to the PATH Variable
To rectify this, add homebrew to the PATH variable by doing the following:
In your terminal, run:
export PATH="/opt/homebrew/bin:$PATH"
Hit the Enter key. Then, run echo $PATH in your terminal to confirm if homebrew was successfully added to the PATH variable.
This returns a list of all the executables found on your laptop. Confirm that homebrew is present in the list. If it is, your terminal will now be able to locate homebrew.
3. Run Brew Install Git Again
Now, in your terminal, run brew install git again and hit Enter.
brew install git
Wait patiently for the download to complete.
You have successfully installed git on your laptop. You can now continue on to set up git in VS Code.
Frequently Asked Questions
What causes the zsh: command not found: brew error?
Zsh: command not found: brew is an error that occurs when a git homebrew hasn’t been set up properly on a device. It often signals that git was not added to the PATH variable during installation, and as a result, can’t be executed.
How do you fix the zsh: command not found: brew error?
There are three steps to fix the zsh: command not found: brew error, including:
- Confirm git is installed:
git --version - Add
homebrewto thePATHvariable: You can do so by running exportPATH="/opt/homebrew/bin:$PATH"in your terminal and thenecho $PATH. - Run brew install again: Enter
brew install gitin your terminal and wait for it to download.
