CentOS: install Git from source

The CentOS repository as of this article contains Git v.1.7.1.3 whereas the latest version of Git is 1.8.5.1 which is quite a difference. If you’re using Git repos collaboratively with other developers or companies then you want to make sure you’re using the most up-to-date version of Git. Installation path will be /usr/local/bin. If git can not be found, temporary add it to your PATH with export PATH="$PATH:/usr/local/bin" or permanently add it to your .bash_profile.

Before installing Git we have to install the Development Tools from the CentOS repository which includes the compiler used to compile the source code. We also need to install some other dependencies to get the Git source to compile and run. Once installed you can simply keep Git up-to-date by using itself to clone the github.com repo into a new folder then run the build and install process again.

sudo yum groupinstall 'Development Tools'
sudo yum install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel
 
wget -O git.zip https://github.com/git/git/archive/master.zip
unzip git.zip
cd git-master
 
make configure
./configure –-prefix=/usr/local
# Skip this if you don't need documentation
make all doc
# With documentation
sudo make install install-doc install-html
# Without documentation
sudo make install
 
# Run Git at the command line to make sure it’s installed properly
git -–version
 
# Keep Git up-to-date
git clone git://github.com/git/git

Leave a Reply