I thought I should mention the very easy Homebrew package installer for Mac OS X. I’ve found it quite simple to use and have not turned back since I blew away my MacPorts.
You can find Homebrew on gitub and you can find the recommended installation instructions there which are as follows.
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
This will download the “go” ruby script and execute it in one go. If you are unsure or just curious and can read ruby code, then you can see this script here.
In brief, this script changes permissions on various directories, downloads the Homebrew install files and installs them under /usr/local
Before I ran this install, I blew away my MacPorts installation using these instructions, which suggests the following…
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
Since Apple does not touch /usr/local I cleaned that out too, since anything in there on my Mac would have been installed by MacPorts. Homebrew installs under /usr/local and I wanted it to be nice and clean. Doing this will depend on what you’ve been up to with your Mac.
Some key files that will be installed by the installer are
This script does all the magic of installing, uninstalling, listing installed packages, showing package information and other tasks.
This directory is where the files are installed for the packages you install. You can see some of the package directories I have installed on this machine.
$ ls -dF1 /usr/local/Cellar/* /usr/local/Cellar/bash-completion/ /usr/local/Cellar/geos/ /usr/local/Cellar/git/ /usr/local/Cellar/mongodb/ /usr/local/Cellar/ossp-uuid/ /usr/local/Cellar/pidof/ /usr/local/Cellar/postgis/ /usr/local/Cellar/postgresql/ /usr/local/Cellar/proj/ /usr/local/Cellar/readline/ /usr/local/Cellar/wget/
Once, you’re installed you should be able to run brew install to install packages.
Packages are first downloaded to /Library/Caches/Homebrew/, so if you do uninstall and re-install, you will not have to re-download them a second time.
Here’s a dump of the files my cache directory.
ls -1 /Library/Caches/Homebrew/* /Library/Caches/Homebrew/bash-completion-1.2.tar.bz2 /Library/Caches/Homebrew/geos-3.2.2.tar.bz2 /Library/Caches/Homebrew/git-126.96.36.199.tar.bz2 /Library/Caches/Homebrew/git-htmldocs-188.8.131.52.tar.bz2 /Library/Caches/Homebrew/git-manpages-184.108.40.206.tar.bz2 /Library/Caches/Homebrew/mongodb-1.6.3-x86_64.tgz /Library/Caches/Homebrew/mysql-5.1.51.tar.gz /Library/Caches/Homebrew/ossp-uuid-1.6.2.tar.gz /Library/Caches/Homebrew/pidof-0.1.4.tar.gz /Library/Caches/Homebrew/postgis-1.5.2.tar.gz /Library/Caches/Homebrew/postgresql-9.0.1.tar.bz2 /Library/Caches/Homebrew/proj-4.7.0.tar.gz /Library/Caches/Homebrew/proj-datumgrid-1.5.zip /Library/Caches/Homebrew/readline-6.1.tar.gz /Library/Caches/Homebrew/solr-1.4.1.tgz /Library/Caches/Homebrew/wget-1.12.tar.bz2
I will demonstrate installing Mongodb, which is a “scalable, high-performance, open source, document-oriented database”. Think “NoSQL”.
brew install mongodb
Here’s the output
==> Downloading https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-1.6.3.tgz ######################################################################## 100.0% ==> Caveats If this is your first install, automatically load on login with: cp /usr/local/Cellar/mongodb/1.6.3-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist If this is an upgrade and you already have the org.mongodb.mongod.plist loaded: launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist cp /usr/local/Cellar/mongodb/1.6.3-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist Or start it manually: mongod run --config /usr/local/Cellar/mongodb/1.6.3-x86_64/mongod.conf ==> Summary /usr/local/Cellar/mongodb/1.6.3-x86_64: 16 files, 83M, built in 2 seconds
A command I really like is the info command.
brew info mongodb
It will give you all the information you need for a particular package for starting, stopping, restarting or other actions pertinent the service you installed. If will be similar to the information output when you first install a package. It’s good to know about this command so that you can always find the maintenance commands.
Here is an example of the info command for the postgresql package.
brew info postgresql
postgresql 9.0.1 https://www.postgresql.org/ Depends on: readline, ossp-uuid /usr/local/Cellar/postgresql/9.0.1 (1229 files, 25M) If builds of Postgresl 9 are failing and you have version 8.x installed, you may need to remove the previous version first. See: https://github.com/mxcl/homebrew/issues/issue/2510 To build plpython against a specific Python, set PYTHON prior to brewing: PYTHON=/usr/local/bin/python brew install postgresql See: https://www.postgresql.org/docs/9.0/static/install-procedure.html If this is your first install, create a database with: initdb /usr/local/var/postgres If this is your first install, automatically load on login with: cp /usr/local/Cellar/postgresql/9.0.1/org.postgresql.postgres.plist ~/Library/LaunchAgents launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist If this is an upgrade and you already have the org.postgresql.postgres.plist loaded: launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist cp /usr/local/Cellar/postgresql/9.0.1/org.postgresql.postgres.plist ~/Library/LaunchAgents launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist Or start manually with: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start And stop with: pg_ctl -D /usr/local/var/postgres stop -s -m fast If you want to install the postgres gem, including ARCHFLAGS is recommended: env ARCHFLAGS="-arch x86_64" gem install pg To install gems without sudo, see the Homebrew wiki. https://github.com/mxcl/homebrew/commits/master/Library/Formula/postgresql.rb
brew list will tell you which packages are installed.
brew help will give you the following
Usage: brew [-v|--version] [--prefix [formula]] [--cache [formula]] [--cellar [formula]] [--config] [--env] [--repository] [-h|--help] COMMAND [formula] ... Principle Commands: install formula ... [--ignore-dependencies] [--HEAD] list [--unbrewed|--versions] [formula] ... search [/regex/] [substring] uninstall formula ... update Other Commands: info formula [--github] options formula deps formula uses formula [--installed] home formula ... cleanup [formula] link formula ... unlink formula ... outdated missing prune doctor Informational: --version --config --prefix [formula] --cache [formula] Commands useful when contributing: create URL edit [formula] audit [formula] log formula install formula [-vd|-i] For more information: man brew To visit the Homebrew homepage type: brew home
I hope you find this quick intro to Homebrew helpful. Please leave a comment to question.