Install Git from source on OS X
Posted: April 5th, 2009 | Author: Jason | Filed under: Version Control | Tags: git, os x | No Comments »My version control system of choice these days is Git. Since it doesn’t come preinstalled on OS X, you have a couple of options to get it: MacPorts, packages, or install from source.
Both MacPorts and packages are viable options, but when new releases of Git are made, they have to be repackaged and distributed. So you can’t install the latest version without waiting until they’re ready. When you install from source, you can get the latest version as soon as it’s released.
This guide will show you how to get the latest source, install Git, install man pages, and enable bash completion. As prerequisites, I’m assuming you’re running OS X Leopard and you have Xcode installed (gcc is required for compilation).
First, figure out the version you want to install. You can determine the latest stable version by visiting the Git home page. Assuming the version you want to install is 1.6.2.2 (the current version at the time of writing this post), perform the following steps:
1. Download the source tarball from kernel.org.
curl -O http://kernel.org/pub/software/scm/git/git-1.6.2.2.tar.gz tar -zxvf git-1.6.2.2.tar.gz cd git-1.6.2.2
2. Configure and install. If you want to install to a different directory, change the prefix option.
cd git-1.6.2.2 make configure ./configure --prefix=/usr/local make all sudo make install
3. Get and install man pages.
curl -O http://www.kernel.org/pub/software/scm/git/git-manpages-1.6.2.2.tar.gz sudo tar -zxvf git-manpages-1.6.2.2.tar.gz -C /usr/local/share/man
4. Enable bash completion for Git. If you don’t have bash-completion installed, skip this step. I have-bash completion installed via MacPorts. Yours may be installed differently, so update your paths accordingly.
sudo cp contrib/completion/git-completion.bash /opt/local/etc/bash_completion.d/git-completion
Congratulations! You now have Git installed. To verify, open up your terminal and run the following command:
git --version
Now, to keep your Git installation up to date, simply follow the same steps with the latest version number and install the latest version over top of your current version.
For convenience, I have packaged up the previous steps in a simple bash script called get_git.sh available on Github, which I use to keep my own Git installation up to date. Feel free to fork and use it as you see fit.
Now that you’re using Git, here are some resources you might want to check out:
- Github – the de rigueur standard for Git hosting and collaboration these days
- GitX – a great Git gui available for OS X (if you’re into that kind of thing)
Leave a Reply