I am stuck in an effort to provide an maintain an up-to-date git release for a collection of CentOS Linux servers. I was hoping to be able to create binary RPMs that I could just have published to a local yum mirror - in order to simply installs, and to easily keep everything up-to-date as part of regular maintenance along with the rest of the OS.

It is a common recommendation to simply install the git binaries from the OS's package manager (yum). However, even under the latest CentOS / RHEL 7, the latest provided packages are stuck at a relatively ancient - compared to the latest 2.7.1. It seems that RPMForge used to provide some updated git packages, but not since EL 6. So it seems that building from source is really the only remaining option here - but using a custom RPM package here to maintain this would be a good idea.

It looks like using Fedora's "mock" for RPM packaging will be the best way of handling this. It seems that the worst of this would be obtaining / creating / maintaining a SPEC file. Fortunately, it seems that Fedora Rawhide will be invaluable for this - as available at https://rpmfind.net/linux/RPM/fedora/devel/rawhide/src/g/git-2.7.0-1.fc24.src.html .

I had success doing a simple rebuild from the SRPM:

$ mock -r epel-7-x86_64 rebuild /tmp/git-2.7.0-1.fc24.src.rpm

However, installation fails due to many conflicts from the existing OS-provided git installation. I wouldn't want to remove / replace the OS-provided versions anyway, at risk of running into compatibility or dependency issues down the road with other OS-provided packages that may expect the older git version. I'd prefer a custom RPM that uses a /usr/local prefix.

Using rpm -qpi against any of native RPMs report that they are (not relocatable) - meaning I can't run rpm with a --prefix flag to install in such an alternate location. However, I don't believe I'd want to depend upon using this anyway, as it would complicate being able to run default installs from yum. I would think that this could be easily customized into the source RPM build, so that the resulting RPMs don't conflict.

I thought this would be as simple as defining an alternate value for the _prefix macro in the SPEC file, as such:

$ mock -r epel-7-x86_64 -D "_prefix /usr/local" rebuild /tmp/git-2.7.0-1.fc24.src.rpm

This looked like it was progressing nicely, until it failed spectacularly - ending with the following errors:

+ sed -e 's@^/builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64@@'
find: '/builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64/usr/share/perl5/vendor_perl': No such file or directory
+ find /builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64/usr/share/perl5/vendor_perl -mindepth 1 -type d
+ sed -e 's@^/builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64@%dir @'
find: '/builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64/usr/share/perl5/vendor_perl': No such file or directory
+ grep Git/SVN perl-git-files
error: Bad exit status from /var/tmp/rpm-tmp.sw2Kfy (%install)

RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.sw2Kfy (%install)
ERROR: Exception(/tmp/git-2.7.0-1.fc24.src.rpm) Config(epel-7-x86_64) 2 minutes 39 seconds
INFO: Results and/or logs in: /var/lib/mock/epel-7-x86_64/result
ERROR: Command failed. See logs for output.
# bash --login -c /usr/bin/rpmbuild -bb --target x86_64 --nodeps  /builddir/build/SPECS/git.spec

Alternatively, if I first extract the SPECS and SOURCES, change prefix to /usr/local (from %{_prefix}) in SPECS/git.spec, then rebuild, things still fail - but at a different spot:

+ install -pm 644 contrib/emacs/git.el /builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64/usr/share/emacs/site-lisp/git
+ install -Dpm 644 /builddir/build/SOURCES/git-init.el /builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64/usr/share/emacs/site-lisp/site-start.d/git-init.el
+ install -pm 755 contrib/credential/gnome-keyring/git-credential-gnome-keyring /builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64/usr/libexec/git-core
install: cannot create regular file '/builddir/build/BUILDROOT/git-2.7.0-1.el7.centos.x86_64/usr/libexec/git-core': No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.CJFTef (%install)
    Bad exit status from /var/tmp/rpm-tmp.CJFTef (%install)

RPM build errors:
ERROR: Exception(git-build/2/git-2.7.0-1.el7.centos.src.rpm) Config(epel-7-x86_64) 1 minutes 37 seconds
INFO: Results and/or logs in: /var/lib/mock/epel-7-x86_64/result
ERROR: Command failed. See logs for output.
 # bash --login -c /usr/bin/rpmbuild -bb --target x86_64 --nodeps  /builddir/build/SPECS/git.spec

(I'm guessing the former attempt with defining the _prefix macro was closer to success than forcefully changing prefix in the SPEC file - as there may now be other usages of _prefix that are still using the default value.)

I'm not exactly sure how to proceed. Is there a different way I should be specifying an alternate installation prefix, or is there something else I can try?

2 Answers 2


I found some guys git repo who had SRPM for git 2.7.2 If that is new enough for you.

I successfully build that on Centos 6.


It creates all the packages and dependencies for me, and I was able to add it to my private repo to install git. I'm guessing from the changelogs on 2.9.3 that you could just bump the version number in the spec file to get 2.9.3. (latest version at time of this writing)

  • Thanks. I was able to build under CentOS 7 "as-is", but again - I seem to be unable to successfully set a /usr/local prefix (with repeated concerns of replacing the OS-provided versions, running into compatibility or dependency issues down the road with other OS-provided packages, etc.)
    – ziesemer
    Aug 21, 2016 at 18:37

It seems your attempt at setting prefix to /usr/local works only partially.

Grab the SRPM for CentOS, unpack it, read it's .spec file over. See where it sets up configuration(s), and fix the prefix there. Get the latest tarball for git, change the references to the source (and version!), try building. Probably most of the patches don't apply, will need to review them all for applicability/need.

Change the name of the package to git-local or some such; if not, chances are (as you saw) that the package manager sees it as a replacement for the official git package, and uninstalls that one when installing yours.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .