Terminal 101: Using MacPorts and Homebrew
Posted 09/17/2012 at 1:35pm
| by Cory Bohon
Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!
The Mac comes with a lot of command line tools, but sometimes you may need a tool that Apple doesn’t ship with OS X. In a previous Terminal 101, we showed you how to install a command line browser with MacPorts, but we didn’t really cover it in detail. Today, however, we want to share two command line package managers: Homebrew and MacPorts.
What is a Package Manager?
A package manager is a tool that automates the process of downloading, installing, configuring, and removing software on your machine. The software will automatically check for dependencies (software needed to build the currently installing app), and will automatically retrieve any needed software for you.
In the case of Homebrew and MacPorts, these are two command line package managers that allow you to download development tools, programming language compilers, and other command line-based tools for your Mac, specifically.
Installing Homebrew
Homebrew is one of the best package management systems for those doing web development because it can install and configure a lot of web-based programming languages and tools on your system, including Perl, wget, git, and more. You can browse the entire list of available packages here.
Before installing Homebrew, it is important to note that you will need to have Apple’s Command Line Tools for Xcode installed. You can download the command line tools here: https://developer.apple.com/downloads (a free developer account is required to access the download section).

To install Homebrew on your Mac, open the Terminal application (Applications/Utilities), and type in the following command:
ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
This is a Ruby script that will automate the download and installation of the Homebrew package manager.

After installation, and to test that Homebrew was installed properly, type “brew” into the command line and press return. If you get the same output as in the screenshot above, with no error messages, then Homebrew is properly installed and configured.
For more information about Homebrew, visit http://mxcl.github.com/homebrew/
Installing MacPorts
The installation of MacPorts is a little easier. However, you still need to have downloaded and installed the Command Line Tools for Xcode. Visit the MacPorts installation page to download the appropriate version for your version of OS X. After downloading, run the installer file.

After the installer has completed, open the Terminal and type “port” followed by the return key. If you don’t get any error message, and instead get output like the screenshot above, then MacPorts has been properly installed and configured.

Installing Command Line Applications with Homebrew

To test Homebrew, we will install the Lynx command line browser to ensure that Homebrew can properly install tools. The proper syntax for installing an application using Homebrew is:
brew install appname
Replace appname in the above statement with “lynx” and type it into the Terminal to install the Lynx web browser.
Installing Command Line Applications with MacPorts

To install an application with MacPorts, you will use the following syntax:
sudo port install appname
Replace appname in the above statement with “lynx” (if you didn’t install it with Homebrew), and type it into the Terminal to install the Lynx web browser with MacPorts instead of Homebrew.

After the installation has finished, Lynx will be installed on your Mac. To use Lynx, type “lynx” into the command line followed by the return key.
For more information about using Lynx, visit out previous post on the topic.
Which package manager should you use?
Which package management system you choose is completely up to you. It is important to remember that some packages (command line applications) are available in MacPorts, while others are available in Homebrew only. Generally, you should only install one package management system on your machine as to avoid confusion.
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.