The Homebrew is a package manager for MacOS or Linux. It installs packages to their own directory and then symlinks into /usr/local. Homebrew formulae are Ruby scripts.

Terminology and Introduction

Term Description Example
Fomula package definition in Ruby … /Formula/foo.rb
Keg installation prefix of a formala /usr/local/Cellar/foo/0.1
opt prefix the active version of a Keg /usr/local/opt/foo
Cellar The directory for all Kegs /usr/local/Cellar
Tap 3rd-part repos of Formulea/ commands /usr/local/Homebrew/Libarary/Tap/…
Bottle Pre-build Keg instead from source stuff-4.8.4.tar.gz
Cask Os native/GUI apps /Applications/…
Brew Bundle install a list for dependencies ~/Brewfile

Homebrew use Git for downloading updates and contributing to the project. It installs packages into the /usr/local/Cellar and formulae in /usr/local/Homebrew/Library....

Brew Commands

For install, remove and search

  • brew list: list all installed formulae
  • brew install <formula>: install a formula
  • brew uninstall <formula>: uninstall a formula
  • brew info <formula>: show info such as version and start/stop commands
  • brew search <text>: search a formulae names
  • brew search: display all locally install

For help

  • brew --version
  • brew help
  • brew help command
  • brew doctor: check potential problems

For bacground sevices:

  • if sudo is passed, operate on /Library/LaunchDaemon that starts at boot. otherwise, operate on ~/Library/LaunchAgents that starts at login.
  • brew services: list all managed services for the current user or root
  • brew services run <formula>|--all: run the service without registering to launch at login/boot.
  • brew services start <formula>|--all: start the service and register it to launch at login/boot.
  • brew services stop <formula>|--all: stop the service and ungister it.
  • brew services restart <formula>|--all: restart and register.
  • brew services cleanup: clean uninstall services.

For update

  • brew update: fetch latest version of homebrew and formula
  • brew outdated: show available updated version
  • brew upgrade: upgrade outdated and unpinned brews
  • brew upgrade <formula>: upgrade a specific formula
  • brew pin <formula>: pin a fomula version
  • brew unpin <formula>: unpin a formula

For cleanup

  • brew cleanup: remove older versions of installed formulae
  • brew cleanup <formula>: remove odler version
  • brew cleanup -n: display all formulae to be removed (dry run)

For tap

  • brew tap: list all installed taps
  • brew tap <usesr/repo>: tap a formula repo form GitHub. It is a shortcut to brew tap user/repo
  • brew tap-info tap: show tap info.
  • brew untap tap: remove a tapped formula repository.

For link and versions

  • brew unlink <formula>: delete command links
  • brew link <formula>: create command links
  • brew switch <formula> <version>: switch a version