Configuring Mac OS X Mountain Lion 10.8

Want to get started with some command-line tools on Mac OS X Mountain Lion? This tutorial covers installing Xcode, Homebrew, and other useful initial configuration.

(Note: If you’re on Mac OS X 10.9, head over to the Mavericks Configuration Guide.)

First steps

Mountain Lion hides the ~/Library folder by default, but it’s easy to make it visible again with the following command (which gets overridden by OS updates and must be run again after each system update):

chflags nohidden ~/Library/

Since Mountain Lion is a full 64-bit system, we’ll save some headaches by letting our compiler know that all compilation should assume 64 bits. Also, since Mountain Lion’s default PATH is /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin, we’ll want to change it so that Homebrew binaries will take precedence over stock OS X binaries. To make these changes, open ~/.bash_profile

vim ~/.bash_profile

… and add:

# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc

Since the above directives will take effect on the next login, let’s go ahead and source the file to ensure it takes effect for the current session:

source ~/.bash_profile

With those first steps out of the way, now it’s time to get the necessary compilation tools in place.

Compiler

Installing development-related software in the past has required the compiler tool-chain that comes with Xcode. Thankfully, if you don’t need or want Xcode, those compiler tools are now available separately, saving download time and about four gigabytes of disk space. Assuming you have your Apple ID credentials handy, head over to the Developer Downloads area, download the Command Line Tools for Xcode, and install it.

Alternatively, there are some reasons you might want the full version of Xcode:

  • To compile the few tools that won’t compile without the full version of Xcode
  • To download and manually compile open-source Mac applications
  • To develop your own Mac/iOS applications

If you full into one of the above categories, download Xcode from either the Developer Downloads area or the Mac App Store. Make sure you’re on a high-bandwidth connection, because Xcode is a massive beast. Once you’ve installed Xcode, launch the Xcode application, visit the app preferences, find the “Downloads” pane, and download the above-mentioned Command Line Tools from within the Xcode application (if you haven’t already installed them).

XQuartz (optional)

Mountain Lion no longer includes X11, which is a required dependency for some tools. That said, there’s no need to install it unless you know you need it. If you find a tool that requires X11, the Apple-sanctioned solution is to download and install XQuartz, an X11 fork. Once it’s been downloaded and installed, log out and back in to ensure that it’s loaded and available.

Homebrew

Sometimes you may need cross-platform software — usually without a GUI and accessible only via the command line — that isn’t readily available via the Mac App Store. As someone who used MacPorts for years, I can’t begin to explain the relative awesomeness that is Homebrew. It’s an indispensable tool that should be in every Mac developer’s arsenal, so let’s fire up Terminal.app and install it:

ruby <(curl -fsSkL https://raw.github.com/mxcl/homebrew/go)

Follow the prompts to download and install Homebrew, entering your administrative password when prompted. Then run the following command to ensure that there aren’t any potential problems with your environment. Some warnings (if any) are informational and not necessary actionable; it’s just a good idea to at least read through and see if anything looks out of the ordinary.

brew doctor

The following command will update to the latest version of Homebrew and its formulae:

brew update

If the “brew update” command produces an error, make sure /usr/local is owned by you and not by root:

sudo chown $USER /usr/local
brew update

Let’s use Homebrew to install some packages that I often find useful:

brew install bash-completion ssh-copy-id wget

You can run brew info ssh-copy-id, for example, if you want to know what those packages do.

Some Homebrew formulae recommend post-installation steps. For example, to activate bash completion, add the following to your ~/.bash_profile:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
fi

There are many other useful Homebrew commands, all of which can be seen by running man brew in the terminal.

Just the basics

These are obviously just the basics. If you have any interest in Python, have a look at my guide to setting up your Python Development Environment on Mac OS X.

What kinds of customizations have you made to your Mountain Lion setup? Leave a comment below!

Comments