How to tell if homebrew is installed on Mac OS X

Ruby on-RailsMacosHomebrew

Ruby on-Rails Problem Overview


I am doing some Rails programming and I consistently see Homebrew referenced in solutions around the web but have never used it.

I also notice Homebrew in the terminal version 2.9 as an option next to "Shell -> New" from the terminal drop down but when I select homebrew and issue commands, they fail.

Usually with the "command not found" error.

Strangely enough I have been unable to locate a simple command to determine whether brew is installed or not.

How do I check to see if Homebrew is already installed on my Mac?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

brew help. If brew is there, you get output. If not, you get 'command not found'. If you need to check in a script, you can work out how to redirect output and check $?.

Solution 2 - Ruby on-Rails

I use this to perform update or install:

which -s brew
if [[ $? != 0 ]] ; then
    # Install Homebrew
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
    brew update
fi

Solution 3 - Ruby on-Rails

The standard way of figuring out if something is installed is to use which.

If Brew is installed.

>>> which brew
/usr/local/bin/brew

If Brew is not installed.

>>> which brew
brew not found

> Note: The "not installed" message depends on your shell. zsh is shown above. bash will just not print anything. csh will say brew: Command not found. In the "installed" case, all shells will print the path.)

It works with all command line programs. Try which grep or which python. Since it tells you the program that you're running, it's helpful when debugging as well.

Solution 4 - Ruby on-Rails

While which is the most common way of checking if a program is installed, it will tell you a program is installed ONLY if it's in the $PATH. So if your program is installed, but the $PATH wasn't updated for whatever reason*, which will tell you the program isn't installed.

(*One example scenario is changing from Bash to Zshell and ~/.zshrc not having the old $PATH from ~/.bash_profile)

command -v foo is a better alternative to which foo. command -v brew will output nothing if Homebrew is not installed

command -v brew

Here's a sample script to check if Homebrew is installed, install it if it isn't, update if it is.

if [[ $(command -v brew) == "" ]]; then
    echo "Installing Hombrew"
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
    echo "Updating Homebrew"
    brew update
fi

Solution 5 - Ruby on-Rails

I just type brew -v in terminal if you have it it will respond with the version number installed.

Solution 6 - Ruby on-Rails

brew -v or brew --version does the trick!

Solution 7 - Ruby on-Rails

Location of the brew where it installed

which brew 

version of home brew install

brew --version

Solution 8 - Ruby on-Rails

[ ! -f "`which brew`" ] && echo "not installed"

Explaination: If brew is not installed run command after &&

Solution 9 - Ruby on-Rails

brew doctor checks if Homebrew is installed and working properly.

Solution 10 - Ruby on-Rails

use either the which or type built-in tools.

i.e.: which brew or type brew

Solution 11 - Ruby on-Rails

Another one possible way:

# Check if Ninja is installed
if ! which ninja > /dev/null
then
echo 'Ninja installation...'
brew install ninja
fi

Solution 12 - Ruby on-Rails

In my case Mac OS High Sierra 10.13.6

brew -v

OutPut-
Homebrew 2.2.2
Homebrew/homebrew-core (git revision 71aa; last commit 2020-01-07)
Homebrew/homebrew-cask (git revision 84f00; last commit 2020-01-07)

Solution 13 - Ruby on-Rails

Yes you can run which brew, but you may have it installed and it says it is not found if you are using zsh. You will need to add it to your .zshrc file.

Solution 14 - Ruby on-Rails

I find it simple to use brew help command to find it is installed or not. There was a user guide on the homebrew download page.

If it is not installed then it will show 'command not found'

If you need to install homebrew then paste this on terminal:

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

Solution 15 - Ruby on-Rails

Once you install Homebrew, type command brew doctor in terminal.

  • If you get the following message:

>Your system is ready to brew

then you are good to go and you have successfully installed homebrew.

  • If you get any warnings, you can try fixing it.

Solution 16 - Ruby on-Rails

Another way to do it is using the "command" builtin tool

if [ "$(command -v brew)" ]; then
    echo "command \"brew\" exists on system"
fi 

Solution 17 - Ruby on-Rails

Maybe your mac don't received the path

enter image description here

Run command below

eval "$(/opt/homebrew/bin/brew shellenv)"

And run to check that work brew help

Solution 18 - Ruby on-Rails

Running Catalina 10.15.4 I ran the permissions command below to get brew to install

sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKmb40View Question on Stackoverflow
Solution 1 - Ruby on-RailsbmarguliesView Answer on Stackoverflow
Solution 2 - Ruby on-RailsDPPView Answer on Stackoverflow
Solution 3 - Ruby on-RailsLiyan ChangView Answer on Stackoverflow
Solution 4 - Ruby on-RailsAamnahView Answer on Stackoverflow
Solution 5 - Ruby on-RailsTravisPView Answer on Stackoverflow
Solution 6 - Ruby on-RailsBappyView Answer on Stackoverflow
Solution 7 - Ruby on-RailsSneha MuleView Answer on Stackoverflow
Solution 8 - Ruby on-RailsbitsView Answer on Stackoverflow
Solution 9 - Ruby on-RailsThomas David KehoeView Answer on Stackoverflow
Solution 10 - Ruby on-Railskaiky25View Answer on Stackoverflow
Solution 11 - Ruby on-RailsYuliaView Answer on Stackoverflow
Solution 12 - Ruby on-RailsAnkit Kumar RajpootView Answer on Stackoverflow
Solution 13 - Ruby on-RailsdaceyView Answer on Stackoverflow
Solution 14 - Ruby on-RailsShanto KunduView Answer on Stackoverflow
Solution 15 - Ruby on-RailsSunny SinghView Answer on Stackoverflow
Solution 16 - Ruby on-RailsDaniel BrancoView Answer on Stackoverflow
Solution 17 - Ruby on-RailsvnguyenView Answer on Stackoverflow
Solution 18 - Ruby on-RailsJames TervitView Answer on Stackoverflow