AmirHd AmirHd - 1 year ago 188
Linux Question

How to install latest version of git on CentOS 6.x/7.x

I used the usual:

yum install git

But it did not install the latest version of git on my CentOS 6.4. So, how can I update to the latest version for CentOS 6.4?


The solution can be applicable to other newly released versions of CentOS such as CentOS 7.x.

Answer Source

Having a look at the blog here I found the solution in one of the comments. Make sure you got the rpmforge repository added to your CentOS yum and just run the flowing command:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras install git

If you already have git installed then use:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras update git

Related question(s):

  1. Facing issues while upgrading git to latest version on CentOS 6.4

Note update:

Thanks to Anthony Hatzopoulos, for git v1.8x you'll need to use git18 as in:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras install git18 

Note update 2:

Also thanks to @Axlrod for the below hint and @Hiphip for the feedback:

Change the rpmforge.repo file to have rpmforge-extras to enabled, yum update git. Otherwise it complained about dependency problems.

Note update 3:

Installing a specific version of git say 2.x I found this nice and easy-to-follow guide on how to download the GIT source and compile it yourself (and install it). If the accepted answer does not give you the version you want, try the following instructions:

(And pasted/reformatted from above source in case it is removed later)

Step 1: Install Required Packages

Firstly we need to make sure that we have installed required packages on your system. Use following command to install required packages before compiling Git source.

# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
# yum install  gcc perl-ExtUtils-MakeMaker

Step 2: Uninstall old Git RPM

Now remove any prior installation of Git through RPM file or Yum package manager. If your older version is also compiled through source, then skip this step.

# yum remove git

Step 3: Download and Compile Git Source

Download git source code from kernel git or simply use following command to download Git 2.0.4.

# cd /usr/src
# wget
# tar xzf git-2.0.4.tar.gz

After downloading and extracting Git source code, Use following command to compile source code.

# cd git-2.0.4
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc
#  or
# echo 'export PATH=$PATH:/usr/local/git/bin' > /etc/profile.d/
# source /etc/bashrc

HINT: Updated method of adding compiled git bin directory to bashrc. Because echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc used "" instead of '', it would expand the current session's value for $PATH instead of keeping it as a variable, and could adversely affect the entire system. At the minimum, it should use '' instead of "" and should really be a separate script in /etc/profile.d/

Step 4. Check Git Version

One completion of above steps, you have successfully install Git in your system. Let use following command to check git version

# git --version

git version 2.0.4

I also wanted to add that the "Getting Started" guide at the GIT website also includes instructions on how to download and compile it yourself:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download