Skip to content

Instantly share code, notes, and snippets.

@m0un10
Last active September 5, 2023 13:42
Show Gist options
  • Save m0un10/c890b5841689e3f3c79972c454f1b60d to your computer and use it in GitHub Desktop.
Save m0un10/c890b5841689e3f3c79972c454f1b60d to your computer and use it in GitHub Desktop.
Installing latest Git on older RedHat Linux derivatives

The default Git that ships with older versions of RedHat-derivates such as (Centos 6, Oracle Linux 6 and of course RedHat 6 itself) may be quite old. If it is a version such as 1.7.1 or earlier, you won't be able to use git with other tools that requirer newer versions such as Jenkins. Below are the steps to install (or upgrade to) a newer version of git. Thanks to Tim for the original article here.

The following should be performed as a root user or with sudo.

If an older Git is already installed, run this to remove it:

yum remove git -y

Install the prerequisite packages and remove the any current Git installation.

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

Download the latest Git installation from kernel.org and unpack it.

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

Build git from source using make then put the binary on the PATH.

cd git-2.9.3
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile.d/git.sh
source /etc/bashrc

Test it, by checking the version.

git --version

If you need to make git available to Jenkins you can add it to the PATH in JENKINS_CONFIG. For example:

echo "export PATH=$PATH:/usr/local/git/bin" >> /opt/jenkins/config/jenkins

If you are unsure where the JENKINS_CONFIG is check the jenkins startup service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment