Building own RPM packages

This article describes how you can set up your own RPM packaging repository and build RPM packages from upstream sources using git-buildpackage-rpm tool.

You may find this article useful if you want to:

  • package your or someone else software in RPM format
  • maintain your set of patches to existing source code and be able to build these as RPM.

Install git-buildpackage-rpm

OpenNode RPM repository can be used:

curl > /etc/yum.repos.d/opennode-tools.repo
rpm --import
yum install git-buildpackage-rpm

Alternatively, you can get latest version of git-buildpackage-rpm from Github repository.

Get upstream sources

Upstream source code will be imported to packaging repository.

Upstream source code archive file should be named foo-1.2.3.tar.gz (or foo-1.2.3.tar.bz2) where foo is program upstream name and 1.2.3 is program version. Archive should contain one directory named foo-1.2.3 with all source code placed inside that.


Get source code archive from Python Package Index:


Get source code archive from Github – ‘develop’ is desired branch or tag name here:

wget -O nodeconductor-develop.tar.gz

Get source code archive from Bitbucket:

wget -O South-0.8.4.tar.gz

Create source code archive from cloned repository using setup.pydist/logan-0.5.9.tar.gz file will be created:

git clone
cd logan
git checkout tags/0.5.9
python sdist

Create source code archive from cloned repository using tar/tmp/logan-0.5.9.tar.gz file will be created:

git clone
cd logan
git checkout tags/0.5.9
tar -czf /tmp/logan-0.5.9.tar.gz --transform 's,^,logan-0.5.9/,' *

Create RPM spec file

RPM spec file describres how to build the RPM package.

RPM spec file should be named foo.spec where foo is RPM package name. Note that

  • RPM package name may be different from program upstream name, example: ‘python-south’ (RPM) vs ‘South’ (upstream)
  • single RPM spec file may be used to build multiple RPM packages.

Refer to Fedora Packaging Guidelines for more info on RPM spec files.

This is a minimal RPM spec file template that will help you to get started:

Name: foo
Version: 0.0.1
Release: 1
Summary: Package foo summary
License: MIT

Package foo description.

Create packaging repository

git init
git remote add origin

– where user is your Github user and foo is packaging repository name.

Import upstream sources

Upstream code and packaging info should be kept in separate branches; default upstream branch name is upstream:

git-import-orig-rpm --no-interactive /path/to/source-archive.tar.gz
git checkout upstream
git push -u origin upstream

Add packaging info

Default packaging branch name is master, however, you may want to use distribution-specific branch names (centos-6, centos-7, trusty etc.) to be able to build multiple packages from one repository. Example for centos-6 branch:

git checkout -b centos-6

Create git-buildpackage-rpm configuration file:

cat > .gbp.conf <<EOF
patch-export = True
patch-numbers = True
patch-export-ignore-path = (.gbp.conf|packaging/.*)

Create packaging directory:

mkdir packaging

Add these files to packaging directory:

  • RPM spec file: foo.spec
  • Unpacked patches, if any: 0001-foo-fix.patch etc.
  • Other files needed to build RPM package, if any: scripts, configs etc.

Check RPM spec file with rpmlint and make sure there are no errors:

rpmlint packaging/foo.spec

Commit changes:

git add packaging
git commit -m 'Added packaging info'
git push -u origin centos-6

All done.

You can now build RPM packages from this packaging repository: