(guest@joequery.me)~ $ |

Install git from source on OS X

This guide shows you how to compile and install git from source on OS X. Building directly from source can be extremely useful if package managers are slow to apply security patches.

This specific procedures avoids OpenSSL errors, such as

openssl/ssl.h' file not found #include <openssl/ssl.h>

Step 1 - Download source

Visit the git source tarballs list. Scroll down and find the git version you are interested in installing. In my case, I wanted to install git version 2.8.1.

In the terminal, execute the following to download the git source. Replace the version numbers in the URL with the desired version numbers.

$ curl "https://www.kernel.org/pub/software/scm/git/git-2.8.1.tar.gz" -o git.tar.gz

Extract the tar that was just downloaded.

$ tar -xf git.tar.gz

cd to the extracted directory (your directory may be different).

$ cd git-2.8.1/

Step 2 - Install OpenSSL Headers

git requires OpenSSL headers to build from source. We will use Homebrew to install the headers.

Follow the "Install Homebrew" instructions.

After the installation has completed, install openssl through brew.

$ brew install openssl

Verify openssl installed successfully.

$ which openssl
# You should see the following output
# /usr/local/bin/openssl

Now link the openssl header files.

$ brew link openssl --force

Step 3 - Install Autoconf

We will use Homebrow to install Autoconf to aid in the compilation process.

$ brew install autoconf

Verify autoconf installed successfully.

$ which autoconf
# You should see the following output
# /usr/local/bin/autoconf

Step 4 - Build git from source

First, create the configuration file updated with our openssl

$ make configure

Compile and build.

$ ./configure && make

While the source code is compiling, the terminal output will resemble something like:

configure: creating ./config.status
config.status: creating config.mak.autogen
config.status: executing config.mak.autogen commands
    CC blob.o
    CC branch.o
    CC bulk-checkin.o
    CC bundle.o
    CC cache-tree.o
    CC color.o
    CC column.o
    CC combine-diff.o
    CC commit.o
    CC compat/obstack.o
    CC compat/terminal.o
    CC config.o
    CC connect.o


$ sudo make install

Step 5 - Verify installation

After the command has executed, verify installation was successful.

$ git --version
# The output should be the version number of the git source downloaded.
# git version 2.8.1

Tagged as git, osx, utilities

Date published - April 18, 2016