How to Install and setup homebrew on MacOS

This tutorial explains about following things

  • How to Install Brew on MACOS
  • Brew command not found

What is the brew command in macOS

Brew alias HomeBrew is an open-source package manager for macOS. It is a command line utility to manage the software or tools on macOS. You can install java, postman chrome, etc manually.

It does not come with MACOS installation, You need to install it manually.

Let’s see how to install brew on macOS Required

  • macOS terminal
  • Xcode installation
  • Bash Shell

How to Install Brew on MacOS

First, check whether the brew is installed or not using the below command

$ brew
zsh: command not found: brew

It gives zsh: command not found: brew if the brew is not installed on macOS.

Following are steps to install brew on macOS

  • Open the terminal application
  • Run the below command to install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

It installed and creates a homebrew folder and adds environment variables to run it anywhere in the command line.

  • /usr/local for MacOS Intel
  • /opt/homebrew for Mac M1 or Bigsu, silicon types

Finally, To verify whether brew is installed correctly or not use below

brew doctor

It gives a successful message

How to update brew on macOS

the brew comes with the latest versions periodically. so you need to update the brew to get the latest version

Run the below command

brew update

Fix for zsh: command not found: brew

On some macOS versions, after installation, Still it shows the message brew command not found.

Check homebrew folder is created in following

  • /usr/local for MacOS Intel
  • /opt/homebrew for Mac M1 or Bigsu, silicon types

open .zshrc file

\vi ~/.zshrc

Add the below to the ~/.zshrc file

PATH=$PATH:/opt/homebrew/bin

Next, restart the terminal or run the source ~/.zshrc command to reload changes

Then, It works perfectly.