January 6, 2015

Linux – How to build an RPM package

To do this, you need to use the rpmbuild command.


You can find all my latest posts on medium.

First you have to install this utility by installing the following package:

$ yum install rpmdevtools

And maybe also the following too:

$ yum install gcc make rpm-build patch
# the following I think are optional:
$ yum pcre-devel openssl-devel rrdtool-devel

You might need to do some patching:

$ patch -p1 --dry-run < /path/to/patch.patch
$ patch -p1 < /path/to/patch.patch

For more info about checkout out:

7 Patch Command Examples to Apply Diff Patch Files in Linux

$ yum info patch
Loaded plugins: rhnplugin, security, ulninfo
*Note* Spacewalk repositories are not listed below. You must run this command as root to access Spacewalk repositories.
Installed Packages
Name        : patch
Arch        : x86_64
Version     : 2.6
Release     : 6.el6
Size        : 172 k
Repo        : installed
From repo   : anaconda-OracleLinuxServer-201507280245.x86_64
Summary     : Utility for modifying/upgrading files
URL         :
License     : GPLv2+
Description : The patch program applies diff files to originals.  The diff command
            : is used to compare an original to a changed file.  Diff lists the
            : changes made to the file.  A person who has the original file can then
            : use the patch command with the diff file to add the changes to their
            : original file (patching the file).
            : Patch should be installed because it is a common way of upgrading
            : applications.

Next run rpmdev-setuptree, this will result in the rpmbuild folder being created:

[root@puppetmaster ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog
[root@puppetmaster ~]# rpmdev-setuptree 
[root@puppetmaster ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  rpmbuild
[root@puppetmaster ~]# tree rpmbuild/
├── RPMS

5 directories, 0 files
[root@puppetmaster ~]# 

How to Create RPM for Your Own Script in CentOS/RedHat

7 Steps to Build a RPM Package from Source on CentOS / RedHat