How Install Git 2.9.5 on CentOS/RHEL 7/6

By Michele Berardi
Picture of the author
Published on
image alt attribute

How to Install Git on CentOS/RHEL

Introduction

Git is a distributed version control system that's widely used for source code management. This guide will walk you through the process of installing Git on CentOS/RHEL, ensuring you have the latest features and security updates.

Step 1 – Install Required Packages

Before installing Git, you need to install several development tools and libraries. These are necessary for compiling Git from source:

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

Step 2 – Download and Install Git

Download the latest stable version of Git. As of writing this article, the latest version is 2.9.5. You can download it using the following commands:

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

Once the tarball is downloaded, compile and install Git:

cd git-2.9.5
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
source /etc/bashrc

Step 3 – Check Git Version

After installation, verify the installed version of Git:

git --version

You should see git version 2.9.5 as the output.

Additional Information

  • Why Compile from Source? Compiling Git from source ensures you have the latest version, which might not be available in the CentOS/RHEL repositories.

  • Configuring Git: After installation, it's good practice to set your Git global configuration:

    git config --global user.name "Your Name"
    git config --global user.email "[email protected]"
    
  • Updating Git: To update Git in the future, simply download the newer version and repeat the installation process.

Conclusion

Installing Git on CentOS/RHEL from source allows you to leverage the latest improvements and features in Git. It's a straightforward process that enhances your development environment, making it ideal for modern version control needs.

Stay Tuned

Want to become a AI pro?
The best articles, links and news related to AI delivered once a week to your inbox.