Installing the Xcode Command Line Tools on Snow Leopard

Update, 29 May 2012: The latest version of the Command Line Tools is “Late March 2012.”

Yesterday, Apple released the Command Line Tools for Xcode package, which installs the headers and utilities necessary to compile Unix software on Mac OS X. This allows non-Cocoa developers to compile applications without downloading and installing Xcode. Sadly, the package is Lion-only; attempting to install it on Snow Leopard will result in an error. Fortunately, you can easily modify the package so that it will install on Snow Leopard systems.

First, you’ll need to download the Command Line Tools package from Apple Developer (free account required; you can use your Apple ID). As of this writing, the package is named “Command Line Tools for Xcode — Late March 2012.” It’s a 180 MB disk image, which pales in contrast to the 4.2 GB Xcode 3.2.6 download. Note that, if you’ve already installed Xcode or the OS X gcc installer, you’ll want to uninstall it before installing the Command Line Tools.

Once you’ve downloaded and mounted the disk image, launch Terminal and type:

cd
mkdir osx-gcc
cd /Volumes/Command\ Line\ Tools
cp -r * ~/osx-gcc

cd ~/osx-gcc
mkdir pkg
mv Command\ Line\ Tools.mpkg pkg/install.mpkg
cd pkg
xar -xvf install.mpkg

Note: It’s important that you use cp -r, rather than simply cp; the former will copy all hidden installation files to the ~/osx-gcc directory. The Command Line Tools.mpkg file is merely a 512 KB descriptor that contains the installation instructions; the actual packages are located in the hidden, aptly-named Packages directory.

Next, open the Distribution file with your favorite text editor. I prefer TextMate (mate Distribution), but you can use vi, emacs, BBEdit, TextWrangler, or even TextEdit (open -a TextEdit Distribution). On line 10, you should see the following:

var majorOSVersion = '10.7';

This specifies the minimum operating system requirement—OS X 10.7 Lion, in this case. Modify the line as follows, save the file, and close your text editor:

var majorOSVersion = '10.6';

You’ve now patched the package so that it will install successfully on Snow Leopard; the final step is to recreate the package file so that it can be read by the installer app:

rm install.mpkg
xar -c . -vf ../install.mpkg
cd ..
open install.mpkg

I’ve used the Command Line Tools to compile autoconf, OpenSSL, and Node on OS X 10.6.8, and the programs work as expected. Remember, however, that this procedure is completely unsupported by Apple, so any problems that you may encounter with the tools are unlikely to be addressed.