CentOS is a fantastic Linux distribution and. It’s stable, and its link to Red Hat means that you can use packages that are noted for their stability under stress. Security updates are also automatically taken care of, thanks again to the association with Red Hat. And of course, it’s extensible with third party repositories.
Unfortunately, this also means that we’re often stuck with extremely outdated packages when the rest of the Linux world has moved on long ago. Take git for example. A tool that almost every programmer is intimately familiar with. A powerful version control system, capable of scaling to projects of any size. It even comes built in with the default installation of CentOS!
Outdated Git Versions on CentOS
The problem however, is that the default version is really out of date. For example, here is the version of git that comes with the default CentOS on DigitalOcean:
You can see here, that it’s version 22.214.171.124 . How far back is that? Well, according to this wiki page:
Version 1.8.5 was released way back in 2014! This article is being written towards the end of 2017. That’s a gap of four years. An eternity in the software development life cycle. Meanwhile, on the official git page, the version that everyone else can download is this:
So while the rest of the world is using v2.14.1, we CentOS users are still stuck on 126.96.36.199. According to Wikipedia, that’s a gap of sixteen versions! The life cycle of CentOS really is pretty slow, and the price we pay for security and stability is hopelessly outdated versions of software. A familiar tradeoff, to be sure.
But let’s say you need the latest version of git? How do we replace the one we already have, with the new one? To do that, let’s do the following.
Step 1: Remove the Existing Version of git
In order to avoid conflict with the newer versions of the software, I’m going to remove the existing git version that ships with CentOS. To do this, simply type:
yum remove git
This will uninstall the existing version of git from CentOS and leave you (temporarily) without a version control system.
Step 2: Install the Dependencies to Build git from Source
In order for us to configure and make the installation for git, we need to have certain pre-requisite packages. These can easily be installed via yum. Here they are:
yum groupinstall "Development Tools" yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel
Once these tools are installed, we’re ready to download the tar files.
Step 3: Download and Extract the Source Code for git
Let’s say we want to install the same version 2.14.1 that everyone else is using. We can go to this site here which contains the compressed sources and get the URL of the one we want:
Copy the URL of the version you want, and download it onto your CentOS server. Then extract it using the following commands:
wget https://www.kernel.org/pub/software/scm/git/git-2.14.1.tar.gz tar -zxf git-2.14.1.tar.gz
Replace the code in bold with your own file name that you got from the above site. This will create a folder on your drive with the source code for git inside it.
Step 4: Install the Git Source Code
Installing from source can be messy. I recommend using a tool like “stow” that will allow you to cleanly uninstall your source software if something goes wrong. “Method 2” in the link shows you how to use stow. To install, first configure and make the software using the following commands:
These two commands can take some time to run. When done, make the install with:
And if you’re using “stow”, use:
make install prefix=/usr/local/stow/git
This completes the installation of git from source
Step 5: Clear the Hashes
If you’ve run the “git” command before, your bash environment might have stored the old path and will prevent you from running the new one and you’ll get an error that says:
bash: /usr/bin/git: No such file or directory
To clear the cache, type the following command:
And now when you run “get –version”, you see the following:
We’ve successfully installed the latest version of git from source and replaced the older one shipped with CentOS!
Is your website slow?
Enter its URL below to find out now: