zsh: command not found: brew

Dorcas Adjeley Laryea - Mar 10 - - Dev Community

My first time setting up git on my Macbook was a few years ago. My second time was this week, and I faced the same error I faced the first time, except I didn't take note of how I fixed it. So I am writing this short article, hoping that the next time I face this issue again, I know where to find a possible solution.

So basically, I'm writing this for me. However, if anyone else faces this error and this helps them too, then that is a bonus.


Setting up git on a new laptop

1. Go to the git download page here.

Download the appropriate version according to your device.

Since I am using a Macbook, I download the version for Mac.

To download, first install homebrew by running in your
terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

2. According to the documentation, after installing homebrew, in your terminal, run:

brew install git
Enter fullscreen mode Exit fullscreen mode

Except, once I run this, it throws an error:
zsh: command not found: brew

However, running git --version confirmed I had git installed:

git --version
Enter fullscreen mode Exit fullscreen mode

git version 2.39.3 (Apple Git-146)

It became clear that homebrew was not added to the PATH variable during installation, therefore shell could not locate the homebrew executable.

To rectify this, add homebrew to the PATH variable by doing the following:

  • In your terminal, run:
export PATH="/opt/homebrew/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

Hit the Enter key.

  • Run:
echo $PATH
Enter fullscreen mode Exit fullscreen mode

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. Now, in your terminal, run brew install git again and hit Enter

brew install git
Enter fullscreen mode Exit fullscreen mode

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. Check out this documentation on how to do that.

. .
Terabox Video Player