Git is a distributed version control system that allows multiple people to work on a project at the same time without overwriting each other’s changes. As of today, it is the de facto standard for version control in the software development industry.

Advertisement

In this guide, we will walk you through the process of installing the latest Git from source on CentOS/RHEL/Fedora. This method is beneficial when you want to use the most recent version of Git that may not yet be available in the default repositories of your operating system.

Prerequisites

Before you begin, you will need:

  • A system running CentOS, RHEL, or Fedora.
  • Root or sudo access to the system.

Step 1: Install the Necessary Dependencies

Before we can build Git from source, we first need to install the software that Git depends on. This includes the ‘Development Tools’ group which provides basic build tools, and some additional libraries Git needs.

Open a terminal window and run the following command:

sudo yum groupinstall 'Development Tools' 
sudo yum install gettext-devel openssl-devel perl-CPAN git perl-devel zlib-devel curl-devel  

Step 2: Download the Latest Git Source

Next, we need to download the source code for the latest version of Git. We’ll do this by cloning the Git source repository.

First, navigate to the directory where you want to download the source code. In this example, we’ll use /usr/src.

cd /usr/src 

Then, clone the Git repository:

sudo git clone https://github.com/git/git.git 

Step 3: Build and Install Git

Now, navigate into the git directory that was created when we cloned the repository:

cd git 

Before building Git, it’s a good idea to check out the latest release tag. This ensures you’re building a stable version of Git, rather than the bleeding-edge master branch. You can see all tags with the command `git tag`, and switch to a tag with `git checkout <tagname<`.

To compile and install Git, use the make and make install commands:

sudo make prefix=/usr/local all 
sudo make prefix=/usr/local install 

This will compile Git and install it under /usr/local.

Step 4: Verify the Installation

Once the installation is complete, you can verify that it was successful by checking the Git version:

git --version 

This should output the version of Git that you just installed.

Conclusion

That’s it! You have successfully installed the latest version of Git from source on your CentOS/RHEL/Fedora system. You can now take advantage of all the latest features and improvements in Git.

Remember, Git is updated frequently, so it’s a good idea to check for new releases regularly. You can do this by navigating to the Git directory (/usr/src/git in this example) and running git pull to fetch the latest changes. Then, simply repeat the build and install steps.

Share.

26 Comments

    • Scott Stirling on

      with git 2.25 too:

      yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
      yum install gcc perl-ExtUtils-MakeMaker
      mkdir /usr/src/git
      cd /usr/src/git
      wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.25.0.tar.gz
      tar xzf git-2.25.0.tar.gz
      cd git-2.25.0/
      make prefix=/usr/local/git all
      make prefix=/usr/local/git install

      [root@hostname git-2.25.0]# /usr/local/git/bin/git –version
      git version 2.25.0

      [root@hostname git-2.25.0]# cat /etc/redhat-release
      Red Hat Enterprise Linux Server release 6.10 (Santiago)

  1. In step 3

    echo “export PATH=/usr/local/git/bin:$PATH” >> /etc/bashrc

    should be replaced by

    echo ‘export PATH=/usr/local/git/bin:$PATH’ >> /etc/bashrc

    with single quotes, otherwise you add your current path to /etc/bashrc instead of updating $PATH

  2. Kaushik Vankayala on

    I am unable to proceed with the first commands itself – pre requisites for git. i am getting the following error;

    [mtr_kvankayala@apiappprod yum.repos.d]$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
    [sudo] password for mtr_kvankayala:
    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    No package curl-devel available.
    No package expat-devel available.
    No package gettext-devel available.
    No package openssl-devel available.
    No package zlib-devel available.
    Error: Nothing to do

    Is there any solution for this?

  3. Isaac Egglestone on

    Unfortunately Compling from source and and installing that way messes up your whole system and I wish people would stop posting these kinds of articles thinking they know what they are doing.
    This is 1990s system admin and its not a good idea to do this anymore pretty much ever.

    So many people have articles showing how to do this, but its nearly the worst thing you can do. Especially if the system is a server.

    It is Especially bad if you do that with multiple programs.

    Why?

    There is a good chance that during a yum update some time later that your system will break a dependency that you compiled the source with.

    It works until its broken, which is one month later when you do a package update, or two months later. Its a ticking time bomb you never know when it will happen but rest assured it will happen eventually.

    On top of this very few packages actually have proper removal feature so uninstalling them is a major pain.
    You have binaries all over your system that were installed by source balls and you don’t have any rpm -qif like feature to figure out which source ball installed them.

    THe proper way is to build an RPM from the source:

    https://www.thegeekstuff.com/2015/02/rpm-build-package-example/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%253A+TheGeekStuff+

    And then install it via yum or rpm.

    Then you can remove it easily and and you will be notified when an upgrade will break your dependencies..

    Please write an article on that and replace this one with it so a bunch of people out there don’t break your system like my junior admin did following your article.

    • Isaac, I understand your concern but please bring the complaint to the responsible party i.e. RedHat for not caring enough to provide a recent version of git out-of-the-box. Your message reads awfully close to shooting the messenger as-is.

    • Your absolutely right. this method will not work eventually. my build system broke this we from a yum update from followoing instructions like this. system has been down for days. These tutorials are not the right way to do it.

  4. I couldn’t pass the step “make prefix=/usr/local/git all” . keep asking me need this need that packages. tried to get still unable to get git on my machine. thanks for your help.

  5. I installed git on red hat 7 according to your tutorial. but it leaded to a fatal error. after I installed git successfully, my p4 (perforce command line) could’t connect to the server, and then I tried to restart the virtual machine to see if it could be modified, but I cannot restart the virtual machine because it became black screen completely in the startup process. then I test install git and restart machine in a clean machine, it produced same result. So I have no way to start my original machine. I am so sad.

  6. Thanks for the tutorial, I have followed the same steps and Installed version 2.9.2 on RHEL.
    But the Version shows as 1.8.3.1, any thoughts on how to fix it?

  7. Vaclav Sobotka on

    I did exactly what TOM B suggested with one more change.

    Either remove old version of git:
    $ sudo yum remove git
    or prepend new git directory to path, instead of appending:
    # echo “export PATH=/usr/local/git/bin:$PATH” >> /etc/bashrc

    If you find yourself in need of sudoing the echo above, use this form:
    $ echo ‘export PATH=/usr/local/git/bin:$PATH’ | sudo tee –append /etc/bashrc > /dev/null

    Tested on CentOS 7 and Git 2.8.0 and works like a charm.

    • I had the same problem with RHEL; thankfully reverted back to old snapshot of the virtual machine(vm ware).This happens as previous PATH goes for toss;needs to be very careful while playing with system files.

  8. I’d already installed git via yum only to realise it was a very old version (1.7) which installs in `/usr/bin` and has precedence in the PATH if you run

    “`
    echo “export PATH=$PATH:/usr/local/git/bin” >> /etc/bashrc
    “`
    The alternative is either running:

    “`
    echo “export PATH=/usr/local/git/bin:$PATH” >> /etc/bashrc
    “`

    So that the version of git in /usr/local/git/bin has priority or running

    “`
    yum remove git
    “`

    So that only 2.7 is installed.

Exit mobile version