Zsh: Command Not Found: Brew Error Solved

Zsh: command not found: brew is an error that occurs when git hasn’t been added properly to the PATH variable during installation on a new device. Here’s how to resolve it.

Written by Dorcas Laryea
Published on Jan. 08, 2025
Developer receiving an error while coding
Image: Shutterstock / Built In
Brand Studio Logo

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

  1. Confirm git is installed:
    git --version
  2. Add homebrew to the PATH variable: You can do so by running export PATH="/opt/homebrew/bin:$PATH" in your terminal, followed by echo $PATH.
  3. 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

More on GitHow to Rename a Git Branch

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.

A tutorial on how to resolve zsh: command not found: brew error. | Video: Technoholic

More on GitGetting Started With Version Control Systems

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

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. 

There are three steps to fix the zsh: command not found: brew error, including:

  1. Confirm git is installed: 
    git --version
  2. Add homebrew to the PATH variable: You can do so by running export PATH="/opt/homebrew/bin:$PATH" in your terminal and then echo $PATH.
  3. Run brew install again: Enter brew install git in your terminal and wait for it to download. 

 

Explore Job Matches.