Homebrew Getting Started

Homebrew is a package manager for macOS systems to install the missing UNIX tools. It provides an easy and flexible way to install the tools that Apple did not include with macOS. Homebrew formulae are simple Ruby scripts and complement macOS based developer machine. We can place Homebrew wherever we like in the system including user’s home directory, and it only installs in the directory except it creates symlinks to their files into /usr/local for the tools to be readily available.

Xcode by Apple provides a suite of software development tools and libraries including GCC compiler which is required by many common Unix-based tools. We need Xcode command line developer tools installed on our macOS system before we begin with Homebrew. Here is the simple command to install the Xcode command line developer tools,

$ xcode-select install

Now we are ready to install Homebrew,

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Here are some of the packages that I install using brew,

$ brew install gpg python python3 node sshuttle checkbashisms shellcheck heroku

It is important to keep the Homebrew and packages up-to-date, so I use following function in my .bash_profile which enables brewUp command on the terminal for quick update,

brewUp() {
  brew update
  brew upgrade --cleanup
  brew cleanup
  brew prune
  brew doctor
}

If there is a need to uninstall the Homebrew, then the following command can be used for the same,

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Below are 5 less known brew commands but you may check the list of all commands that brew provides at: http://docs.brew.sh/Manpage.html

  1. Homebrew by default collects the analytics data but brew analytics (on|off) lets us turn the setting on or off.

  2. brew deps --tree shows the dependency tree of a package. It is nice to know the dependencies of a package before actually installing it.

  3. brew ls --full-name --versions shows the list of all packages and their versions including the dependencies but if you like to see the list of packages that you installed and not the dependencies than brew leaves is a handy way to do so.

  4. brew outdated shows the packages that have an updated version available. It is nice to know before running brew upgrade.

  5. If you are working on a project that requires a specific version of a package and you want to ensure that package does not get upgraded during the brewUp command, then brew pin comes handy to prevent from being updated when issuing the brew upgrade command.

Please provide any feedback using the comments below, and I invite you to check out following posts.