Building Git on Mac OS X
2 August 2007, early evening
Update September 18th 2016: You should probably just `brew install git` to install git now. Also, OS X ships with git.
This is a brief guide for those who want to build and install Git under MacOS X. The install process is fairly straightforward. The only hiccup is that the development environment for MacOS X 10.4 doesn’t come bundled the Expat XML Parser. I’m not sure who these instructions will be helpful to, as most people bothering to install Git probably know what they’re doing.
If you follow the steps below you will end up installing Git in /usr/local
. If you haven’t already done so, make sure that /usr/local/bin is in your $PATH. Open up your .bash_login
file and add the following, if you don’t see the path there already:
export PATH="/usr/local/bin:$PATH"
The search path is what your shell uses to determine the location of programs it can run. When you type git
in the command line, it will scan through the various directories it knows applications are stored looking for git
. The which
command can be used to determine where an application is running from — i.e. after you have installed Git, the command which git
should return /usr/local/bin/git
.
Before we can build Git, we will need to download, build, and install the Expat XML parser. If you are on Leopard you can skip this step. The latest version of the library is 2.0.1, which can be downloaded from the project’s Sourceforge site. Once downloaded, open a terminal window and change to the directory the file is located. You’ll need to run the following commands:
tar xvzf expat-2.0.1.tar.gz
cd expat-2.0.1
./configure --prefix=/usr/local
make
sudo make install
This will build and install the Expat library and header files in /usr/local
, which is where you should be installing 3rd party libraries such as this. The first command extracts the source code from the archive you downloaded. The configure
script is used to simplify building applications and libraries across multiple platforms. configure
will perform some tests to make sure your system is capable of building the library, and will generate the Makefile used in the actual compilation process. make
is what actually builds the program, executing all the commands needed to turn the source code into a working program; sudo make install
is what actually copies the library and header files to their final locations. The reason we need to run make install
with super-user privileges is that your normal account doesn’t have write access to /usr/local/
.
Once done, you can now build Git. The process is similar to what was done to build the Expat library. You can download the latest version of Git from its home page — currently this is version 1.5.2.4. Once downloaded, open up your terminal again and change to the directory the archive is stored. You’ll need to run the following commands:
tar xvzf git-1.5.2.4.tar.gz
cd git-1.5.2.4
make configure
./configure --prefix=/usr/local
make all
sudo make install
You can erase the source directories, git-1.5.2.4
and expat-2.0.1
, if you are so inclined.
You now have a working copy of Git. You can now type Git on the command line to see what all the fuss is about. If you have no clue what to do next, check out the tutorial online.
(Note: I haven’t covered building and installing the documentation here, as it is more trouble than it’s worth — trusts me. All the documentation is available online.)
Update 0ct 28th: You do not need to download and install Expat for Leopard. Expat comes installed Leopard.
Update March 1st 2008: See this comment below if the build process complains about gettext. I believe this is a requirement of the tcl-tk GUI Git ships with.
Update March 10th 2010: This advice on installing the man pages without building works perfectly.
Thank you.
by cvk_b on August 13 2007, 5:42 am #
Thanks, really helpful. One few comment:- missing the: “
to the end of export PATH=”/usr/local/bin:$PATH
by Dilgreen on August 15 2007, 12:48 pm #
I get close, but I crash and burn with the make all, when I get:
/usr/bin/ld: warning /sw/lib/libiconv.dylib cputype (18, architecture ppc) does not match cputype (7) for specified -arch flag: i386 (file not loaded)
/usr/bin/ld: Undefined symbols:
_libiconv
_libiconv_close
_libiconv_open
Something is awry? I read that I might have “stale” MacPorts on another link… but I can’t find the /opt directory that would have these ports from my prior ppc life.
by macduffchief on August 23 2007, 9:43 pm #
What exactly are you using MacPorts for? You shouldn’t need to use it at all if you follow the instructions above.
by ramanan on August 24 2007, 12:37 am #
Perfect. Thank you.
by Walker Hamilton on August 24 2007, 10:16 am #
Worked perfectly for me as well. Thank you.
I had been trying to decide between Git and Mercurial. Since I found this tutorial—I’ll be trying Git first.
by Trey Piepmeier on September 8 2007, 10:46 am #
Thanks very much for this tutorial! I really ought to learn the general means to install third party packages though— I think I’ve established the pattern from your tutorial (usr/local), but far too late! When I just got this mac book, I was entirely new to unix-like operating systems having been fed on windows for a decade. So there are a few path issues and incorrectly installed packages from that time. I’ll have to go through and weed them out soon…
by Eddie Ma on December 7 2007, 6:02 pm #
I had a lot of trouble building git, but it was not due to your excellent instructions. As it turned out when I installed this new Intel iMac I transferred information from my old G5 during setup. This included the old /opt structure and libraries from Macports, etc. These libraries had an architecture conflict.
Git built fine when I removed the old /opt directory.
Thanks
by Ian Joyner on January 14 2008, 6:24 pm #
Great!! Brief. To the point, and it worked. Thanks
by Jack on February 2 2008, 12:44 am #
UGH.. I tried doing this on OS 10.4.11. Have developer tools installed and everything. Expat installed no problem, but doing make all on git I get:
Generating catalog po/de.msg
msgfmt —statistics —tcl po/de.po -l de -d po/
make1: msgfmt: Command not found
make1: *** [po/de.msg] Error 127
make: *** [all] Error 2
Apparently I dont have msgfmt installed..yet all my googling for getting it on my machine turn up fruitless..
help!
by Stevie on February 8 2008, 11:18 am #
I installed gettext and all is well..
by Stevie on February 8 2008, 10:47 pm #
Strange, thanks for the info.
by ramanan on February 8 2008, 10:54 pm #
Worked great on my 10.4.10 Mac, Thanks!
by Steffen on February 9 2008, 7:51 pm #
Thanks! Worked for me fine.
by Kevin on February 20 2008, 7:33 am #
I stand corrected. I too had to follow Stevie’s advice and install gettext.
by Kevin on February 20 2008, 7:45 am #
Thanks for the note, Stevie. On 10.5.2 I got the same error with msgfmt, installed gettext, and then git built fine.
(gettext takes a long time to build!)
by Phrogz on March 1 2008, 3:07 pm #
I had the same problem as Stevie. Turns out I had a version of msgfmt hiding in an old Fink /sw directory. I deleted it and everything built fine.
by Sean O on March 11 2008, 7:42 pm #
Thank you
by Craig on March 12 2008, 12:04 pm #
Gr8 advice! Thanks so much!
Needed Git to use with Heroku..
by William Teoh on April 24 2008, 12:50 am #
I think installing the manpages is easy. Just grab an archive from: http://kernel.org/pub/software/scm/git/git-manpages-1.5.5.1.tar.bz2
(of course update the version number for your installation.)
Then copy those files into your man page directory. If you installed git to /usr/local then you will want to copy those files into /usr/local/man.
Then make sure that your $MANPATH is setup correctly.
by David J. on May 2 2008, 1:44 pm #
Nice tip: having the build generate them is a pain. There is this endless sea of dependencies on OS X that I couldn’t be bothered to sort out.
by Ramanan on May 2 2008, 1:47 pm #
perfect,
can i build it as a .so?
by anirudha on June 10 2008, 3:01 pm #
This tutorial was great – I was pleasantly surprised how quickly I had git and then git-gui up and running… now, just need to get my head around git properly :)
by Property For Sale Egypt on July 3 2008, 12:38 pm #
I recommend you check out the peepcode book on Git. It’s pretty good.
by ramanan on July 3 2008, 1:23 pm #
Thanks worked like a charm!
by Mark Story on September 12 2008, 7:33 pm #
Well written and concise. Very nice style and thanks for increasing the SNR.
by Luke Griffiths on September 27 2008, 2:56 pm #
Thank You Very Much! well written and worked like a charm. Again, Thanks.
by Kash on October 28 2008, 8:05 pm #
Thanks for the nice write-up and explanation of the build process into the usr/local folder.
This worked perfectly for me on os 10.5.6. Did not need to install anything but git.
I’m new to mac and am just learning why usr/local is a good place for some tools.
by John on March 23 2009, 8:39 pm #
I just solved this:
/usr/bin/ld: warning /sw/lib/libiconv.dylib cputype (18, architecture ppc) does not match cputype (7) for specified -arch flag: i386 (file not loaded)
/usr/bin/ld: Undefined symbols:
_libiconv
_libiconv_close
_libiconv_open
By doing this: – Added the line NO_FINK=1 to the Makefile file
by abirmingham on December 17 2009, 8:34 pm #
thanks!
worked for me too on os x 10.4.11 with expat 2.0.1 and git-1.5.2.4.
didn’t work for newer version git-1.6.5.
by susi on November 8 2010, 4:57 am #
There might be slight changes in the newer version of git. I’ll try and see what’s changed tonight.
by ramanan on November 8 2010, 9:17 am #
I built things without any problems. I’m running Snow Leopard though. I’m not sure what would have changed.
by ramanan on November 9 2010, 3:18 pm #
Oreeka, in Blackburn Lancashire, are a bunch of lame ass SEO spammers.
[ed. fixed this comment.]
by web development lancashire on February 8 2011, 5:09 am #