Homebrew is a package management system that simplifies the installation of software on the Mac OS X operating system. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility. In 2012, Homebrew had the largest number of new contributors on GitHub.
Official Website brew.sh
$ sudo su $ curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local
$ brew update
$ cd `brew --prefix` $ rm -rf Cellar $ brew prune $ rm `git ls-files` $ rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions $ rm -rf .git $ rm -rf ~/Library/Caches/Homebrew
If you installed MacPorts can't install homebrew, you must first uninstall MacPorts
$ sudo port -f uninstall installed $ sudo rm -rf \ /opt/local \ /Applications/DarwinPorts \ /Applications/MacPorts \ /Library/LaunchDaemons/org.macports.* \ /Library/Receipts/DarwinPorts*.pkg \ /Library/Receipts/MacPorts*.pkg \ /Library/StartupItems/DarwinPortsStartup \ /Library/Tcl/darwinports1.0 \ /Library/Tcl/macports1.0 \ ~/.macports
Error: Failed to update tap: homebrew/dupes
$ brew untap homebrew/dupes $ brew untap homebrew/versions $ brew prune $ brew tap homebrew/dupes $ brew tap homebrew/versions
Starting and Stopping Background Services
launchctl loads and unloads services that start at login. In OS X, these services are represented by files ending with
.plist (which stands for "property list"). These plists are usually stored in either
/Library/LaunchAgents. You load them (i.e. tell them to start at login) with
launchctl load $PATH_TO_LIST and unload them with
launchctl unload $PATH_TO_LIST. Loading a plist tells the program it represents (e.g.
redis) to start at login, while unloading it tells the program not to start at login.
This post-install message from Homebrew may look familiar:
To have launchd start mysql at login: ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents Then to load mysql now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist Or, if you don't want/need launchctl, you can just run: mysql.server start
Doing all that takes too long, and I can never remember where Homebrew plists are. Fortunately, Homebrew includes a lovely interface for managing this without using
launchctl or knowing where plists are.
Install brew services by tapping homebrew/services (one time):
$ brew tap homebrew/services
Here's an example usage:
$ brew services start mysql ==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
Behind the scenes,
brew services start is doing everything in the post-install message above. First it runs
ln -sfv ... for you. Then it runs
aunchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist. It Just Works.
We can easily restart a service:
brew services restart mysql Stopping `mysql`... (might take a while) ==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql) ==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
See everything we've loaded:
postgresql started 305 /Users/xuri/Library/LaunchAgents/homebrew.mxcl.postgresql.plist memcached started 288 /Users/xuri/Library/LaunchAgents/homebrew.mxcl.memcached.plist mysql started 299 /Users/xuri/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Note that the list of services includes services you started with
launchctl load, not just services you loaded with
Let's say we uninstalled MySQL and Homebrew didn't remove the plist for some reason (it usually removes it for you). There's a command:
$ brew services cleanup Removing unused plist /Users/gabe/Library/LaunchAgents/homebrew.mxcl.mysql.plist