Coder Perfect

Installing the most recent version of git on CentOS 8.x/7.x/6.x

Problem

I used the standard:

yum install git

On CentOS 6, it did not install the latest version of git. How can I get the most recent version of git on CentOS 6? The solution can be used with newer CentOS versions, such as CentOS 7.

Asked by AmirHd

Solution #1

You can install Git 2.x using WANDisco’s CentOS repository: for CentOS 6, for CentOS 7, and for CentOS 8.

WANDisco’s most recent version is 2.22.0, which was released on March 2, 2020.

Answered by Joseph Leedy

Solution #2

Looking through the comments on this blog, I discovered the answer in one of them. Simply perform the flowing command after adding the rpmforge repository to your CentOS yum:

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

Use: if you already have git installed.

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

Related question(s):

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

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

Thanks also to @Axlrod and @Hiphip for the following suggestions and feedback:

Concerned about dependency issues.

How to Install Git 2.0.5 on CentOS/RHEL 7/6/5 and Fedora 22/21

(I also copied/reformatted from the aforementioned source in case it was taken down later.)

Install the required packages first.

To begin, we must ensure that all essential packages have been installed on your system. Before compiling Git source, run the following command to install essential packages.

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

Step 2: Remove the old Git RPM.

Remove any previous Git installations using the RPM file or the Yum package management. If your prior version was constructed from source as well, you can skip this step.

# yum remove git

Step 3: Get Git Source and Compile It

Download the source code for git from kernel git or use the command below to get 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

Use the following command to build Git source code after downloading and extracting it.

# 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

Step 4: Verify the Git Version

You have successfully installed Git in your system after completing the above steps. To check the git version, run the following command.

# git --version

git version 2.0.4

I also wanted to point out that the GIT website’s “Getting Started” tutorial offers instructions on how to download and create it yourself:

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

Answered by AmirHd

Solution #3

The ius repository, which contains a reasonably up-to-date git, is maintained by Rackspace, but the stock git must first be removed.

Instructions for CentOS 6 or 7 (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}.rpm
yum 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 that using git-all instead of git-core will frequently install an older version. Instead, try git224-all.

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

Answered by Mark Visser

Solution #4

I came across this helpful and simple guide on how to download the GIT source code and create it yourself (and install it). If the acceptable response does not provide the desired result, try the following steps:

How to Install Git 2.0.5 on CentOS/RHEL 7/6/5 and Fedora 22/21

(I also copied/reformatted from the aforementioned source in case it was taken down later.)

Install the required packages first.

To begin, we must ensure that all essential packages have been installed on your system. Before compiling Git source, run the following command to install essential packages.

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

Step 2: Remove the old Git RPM.

Remove any previous Git installations using the RPM file or the Yum package management. If your prior version was constructed from source as well, you can skip this step.

# yum remove git

Step 3: Get Git Source and Compile It

Download the source code for git from kernel git or use the command below to download Git 2.5.3.

# cd /usr/src
# wget https://www.kernel.org/pub/software/scm/git/git-2.5.3.tar.gz
# tar xzf git-2.5.3.tar.gz

Use the following command to build Git source code after downloading and extracting it.

# cd git-2.5.3
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# echo 'pathmunge /usr/local/git/bin/' > /etc/profile.d/git.sh 
# chmod +x /etc/profile.d/git.sh
# source /etc/bashrc

Step 4: Verify the Git Version

You have successfully installed Git in your system after completing the above steps. To check the git version, run the command below.

# git --version

git version 2.5.3

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

Answered by Pytry

Solution #5

When installing non-standard software or replacing distributed components, I prefer to create rpm packages for CentOS. I recommend using Mock to generate a clean build environment for this.

The procedure is:

cat /etc/yum.repos.d/LocalFile.repo
# LocalFile.repo
#
#  This repo is used with a local filesystem repo.
#
# To use this repo place the rpm package in /root/RPMS/yum.repo/Packages.
# Then run: createrepo --database --update /root/RPMS/yum.repo.
#
# To use:
#  yum --enablerepo=localfile [command]
#  
# or to use only ONLY this repo, do this:
#
#  yum --disablerepo=\* --enablerepo=localfile [command]

[localfile]

baseurl=file:///root/RPMS/yum.repo name=CentOS-$releasever – Local Filesystem repo # Before persistently enabling this repo see the priority note below. enabled=0 gpgcheck=0 # When this repo is enabled all packages in repos with priority>5 # will not be updated even when they have a more recent version. # Be careful with this. priority=5

You may also need to manually install extra dependant packages from the regular repositories, such as perl-TermReadKey.

Answered by James B. Byrne

Post is based on https://stackoverflow.com/questions/21820715/how-to-install-latest-version-of-git-on-centos-8-x-7-x-6-x