Installing Git on Snow Leopard

These are instructions for compiling and installing Git, a free, fast, and efficient distributed version control system, on Mac OS X 10.6 (Snow Leopard).

The benefits of manually building Git yourself in /usr/local are detailed here and here.

Prerequisites

Before following these instructions, you will need:

  1. Mac OS X 10.6 Snow Leopard
  2. The latest Xcode Tools (from the Snow Leopard DVD or downloaded from Apple — the 10.5 version won’t work)
  3. Confidence running UNIX commands using the Terminal

If you want to learn more about UNIX and the command line, check out my PeepCode screencast on this topic.

Step 1: Set the PATH

Launch Terminal.app from the /Applications/Utilities folder.

We need to set your shell’s PATH variable first. The PATH variable determines where your system searches for command-line programs. Using the editor of your choice, create and edit a file in your home directory named .profile (note the “.” preceding the filename).

If you’re using TextMate like you should be and have installed the UNIX mate command, then you can create and start editing the file like this:

mate ~/.profile

To the end of this file, add the following line (or verify that it’s already there):

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

Close and save the file and run this command to load the new setting into your current shell:

source ~/.profile

To verify that you’ve updated your path, enter the following command:

echo $PATH

You should see /usr/local/bin at the beginning of the line returned by the system.

Step 2: Download

We’re going to create a folder to contain the files we’re about to download and compile. If you want, you can delete this folder when you’re done, but keeping it around makes it easier to re-install (or uninstall) these apps later.

Make the new folder:

mkdir ~/src
cd ~/src

Download Git like this:

curl -O http://kernel.org/pub/software/scm/git/git-1.6.4.2.tar.bz2

Step 3: Compile and Install

Build and install Git like this:

tar xzvf git-1.6.4.2.tar.bz2
cd git-1.6.4.2
./configure --prefix=/usr/local
make
sudo make install
cd ..

To verify that Git is installed and in your path, just type:

which git

You should see:

/usr/local/bin/git

If you do, this means Git is ready to go. Just type git to get started. If you saw something different, you haven’t set your path correctly. Go back and try again.

Boom. You now have a custom-built Git. Fork at will.

More articles in the Archive →