Homebrew the Package Installer for Mac

How to use and install Homebrew command line package installer.

Posted by Kirk on 4 January 2016

Homebrew is the very easy package installer for OS X. It's really easy to use and in my opinion it's superior to MacPorts. It would be wise to get rid of your MacPorts installation, if you have one, prior to proceeding, see the instructions below.

Uninstalling MacPorts

In case you want to clean out your MacPort installation, as mentioned above do 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

As Apple does not touch /usr/local you can clean that out as well, as anything there would have been put there by MacPorts, and since Homebrew installs under /usr/local it's good if it is clean. Of course this all depends what you have been doing with your Mac.

Installing Homebrew

You can find Homebrew's github page here and of course the recommended installation instructions, which at the command line is:

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

This will download the "go" ruby script and execute it all in one go. In summary the script changes permissions on various directories, downloads the Homebrew install files and installs them under /usr/local.

Some key files that will be installed by the Hombrew installer are:

/usr/local/bin/brew

The script does all the heavy lifting of installing, uninstalling, listing installed packages and displaying package information as well as other tasks.

/usr/local/Cellar

This is the directory where files are installed for all your installed packages.

Using Homebrew

This command will list all your package directories on your machine:

ls -dF1 /usr/local/Cellar/*

The out put of that command will look something like this:

/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/dnsmasq/
/usr/local/Cellar/readline/
/usr/local/Cellar/wget/

Once installed, all that is required is to run brew install to install new packages.

Packages are initially downloaded to /Library/Caches/Homebrew/, so if you uninstall and then reinstall the package will not be downloaded a second time. To get a listing of your cache directory use:

ls -1 /Library/Caches/Homebrew/*

However if you use a cleaner program it may clean out the cache periodically.



Posted in:
OSX  

comments powered by Disqus