[ruby-on-rails] How to tell if homebrew is installed on Mac OS X

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?

This question is related to ruby-on-rails macos homebrew

The answer is


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

brew doctor checks if Homebrew is installed and working properly.


use either the which or type built-in tools.

i.e.: which brew or type brew


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.


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)

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


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

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


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.


Another one possible way:

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

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/*

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

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


Examples related to ruby-on-rails

Embed ruby within URL : Middleman Blog Titlecase all entries into a form_for text field Where do I put a single filter that filters methods in two controllers in Rails Empty brackets '[]' appearing when using .where How to integrate Dart into a Rails app Rails 2.3.4 Persisting Model on Validation Failure How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? Rails: Can't verify CSRF token authenticity when making a POST request Uncaught ReferenceError: React is not defined

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to homebrew

dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac How can I install a previous version of Python 3 in macOS using homebrew? SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 pip3: command not found env: node: No such file or directory in mac Stuck at ".android/repositories.cfg could not be loaded." Brew install docker does not include docker engine? What do raw.githubusercontent.com URLs represent? Homebrew refusing to link OpenSSL