Create an RPM package from the Git source

Welcome to post 9 of my 100 day challenge. Checkout my introduction for some background.

In this post I will show you how to create an RPM package from the Git source

Use this tutorial when you can’t find an RPM package new enough for you to install from the standard repos. In this example I will show you how to create an RPM package of Git from the latest Git source.

Step-by-step guide

  1. Install the RPM build package:
    yum install -y rpm-build
  2. Create the RPM build folder structure in your home directory (or a directory of your choosing, i.e /opt/):
  3. Install the required Git dependencies:
    yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
    yum -y install  gcc perl-ExtUtils-MakeMaker
  4. Download and extract the Git source from the official location and move it to ~/rpmbuild/SOURCES:
    mkdir -p ~/src && cd ~/src
    wget https://www.kernel.org/pub/software/scm/git/git-2.2.2.tar.gz
    tar -xzvf git-2.2.2.tar.gz
    mv git-2.2.2.tar.gz ~/rpmbuild/SOURCES
  5. Locate the .spec file and use it to build the RPM package:
    cd ~/src/git-2.2.2 && ls | grep *.spec
    rpmbuild -ba git.spec
    The creation of this RPM package will take quite a while because by default any documentation found will be built as well. If you do not wish to build the documentation you can skip it by passing –without docs to rpmbuild
  6. Finally list the ~/rpmbuild/RPMS directory and you will see the packages that have been built:
    ~:$ ls ~/rpmbuild/RPMS/x86_64/
    git-2.2.2-1.el6.x86_64.rpm      git-arch-2.2.2-1.el6.x86_64.rpm  git-debuginfo-2.2.2-1.el6.x86_64.rpm  git-gui-2.2.2-1.el6.x86_64.rpm  git-svn-2.2.2-1.el6.x86_64.rpm  perl-Git-2.2.2-1.el6.x86_64.rpm
    git-all-2.2.2-1.el6.x86_64.rpm  git-cvs-2.2.2-1.el6.x86_64.rpm   git-email-2.2.2-1.el6.x86_64.rpm      gitk-2.2.2-1.el6.x86_64.rpm     gitweb-2.2.2-1.el6.x86_64.rpm
  7. To install or upgrade from these RPM packages see Installing Git from an RPM file.
  8. Useful RPM commands:
    # Install
    rpm -ivh {rpm-file}
    # Upgrade
    rpm -Uvh {rpm-file}
    # Remove with dependencies
    rpm -ev {package}
    # Remove and ignore dependencies
    rpm -ev --nodeps {package}
If you come across any errors during the build process it is more than likely related to a missing dependency, make sure that you look up the package you are trying to build and insure that you have satisfied all dependencies required.

Subscribe to my feed either by E-mail or by RSS to receive updates as they happen.

Can you improve on any of the tips I’ve discussed here? If you can let me know in the comments.

Jason Edwards