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

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


You can use WANDisco's CentOS repository to install Git 2.x: for CentOS 6, for CentOS 7

  1. Install WANDisco repo package:

    yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm- or -yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm- or -yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
  2. Install the latest version of Git 2.x:

    yum install git
  3. Verify the version of Git that was installed:

    git --version

As of 02 Mar. 2020, the latest available version from WANDisco is 2.22.0.


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:

http://tecadmin.net/install-git-2-0-on-centos-rhel-fedora/

(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 https://www.kernel.org/pub/software/scm/git/git-2.0.4.tar.gz# 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/git.sh## source /etc/bashrc

HINT 1: 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/

HINT 2 (@DJB): /usr/local/git/bin before $PATH, since the older version of git was already on $PATH: export PATH=/usr/local/git/bin:$PATH

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 --versiongit 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:

http://git-scm.com/book/en/v2/Getting-Started-Installing-Git


Rackspace maintains the ius repository, which contains a reasonably up-to-date git, but the stock git has to first be removed.

CentOS 6 or 7 instructions (run as root or with sudo):

# retrieve and check CENTOS_MAIN_VERSION (6 or 7):CENTOS_MAIN_VERSION=$(cat /etc/centos-release | awk -F 'release[ ]*' '{print $2}' | awk -F '.' '{print $1}')echo $CENTOS_MAIN_VERSION# output should be "6" or "7"# Install IUS Repo and Epel-Release:yum install -y https://repo.ius.io/ius-release-el${CENTOS_MAIN_VERSION}.rpmyum install -y epel-release # re-install git:yum erase -y git*yum install -y git-core# check version:git --version# output: git version 2.24.3

Note: git-all instead of git-core often installs an old version. Try e.g. git224-all instead.

The script is tested on a CentOS 7 docker image (7e6257c9f8d8) and on a CentOS 6 docker image (d0957ffdf8a2).