How to Install Git on CentOS/RHEL
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:
tar xzf git-2.9.5.tar.gz
Once the tarball is downloaded, compile and install Git:
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
Step 3 – Check Git Version
After installation, verify the installed version of Git:
You should see
git version 2.9.5 as the output.
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.
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.