How to Build an RPM

Updated -

If you create software to run in Red Hat Enterprise Linux, packaging it into an RPM makes it easier for you to manage, distribute, verify and update that software. This Tech Brief provides a basic HOWTO for creating an RPM package, signing it, distributing it (via a yum repository), and verifying its contents. It does this by illustrating the process using an existing source code package.

If you are taking the RHCE exam, this Tech Brief aims at covering the information needed for the RPM building requirement.

For more information about RPM, start with the following resources:


  • Component
  • rpm


Wow, this is definitely the most recent and comprehensive article on building RPMS. Thanks Chris. I will study it carefully over the coming days. You're a brilliant techie.

Excellent! Thanks Lina. Let me know if you have any questions or problems when you try it out.

Hi Chris,


This may be fixed in newer versions but on my build systems (including CentOS 5.6) a regular user needs to create an ~/.rpmmacros file before being able to extract a source RPM to his/her local build environment.

Without this you get:

$ rpm -ihv python-xlrd-0.6.1-5.el4.src.rpm

error: cannot write to %sourcedir /usr/src/redhat/SOURCES


Therefore I would add:

$ cp -R /usr/src/redhat rpm

And add the following to ~/.rpmmacros

# Path to top of build area
%_topdir    %(echo ${HOME}/rpm)
%_tmppath   %{_topdir}/tmp


Though not relevant for the RHCE exams perhaps it is useful to mention building packages with mock ( instead of plain rpmbuild.


Using a mock environment allows you to build packages for more than one distribution/release/architecture while the above guide requires as many build environments as you have different platforms.


Some more links I found useful:





Thanks for the comments Bram. Someone using CentOS should refer to your note.


They must have changed the default value for %topdir for RHEL6. In RHEL6, when I created a new user account and ran rpm -i on my source code RPM as that user and it created the rpmbuild directory structure under the user's home directory by default. Maybe you need to upgrade to RHEL6 ;-)


Not a bad idea, however, to mention that you can set %topdir to be anywhere you prefer build directories to go. I'll probably note the next time I go to rev this document. Thanks!

Hey man..


I downloaded this to see how well it was written.. and look who I find!  


I'll hit you on FB...



Hey man..


I downloaded this to see how well it was written.. and look who I find!  


I'll hit you on FB...



Nice to hear from you Tweeks. I hope to see you hanging out here in the online user groups.


I wrote the RPM tech brief one evening because someone was concerned about the RPM building requirement that has been added to the list of potential topics on the RHCE exam. Using an existing source RPM, I just reviewed the pieces of an RPM, then how to build, sign and share it. Didn't really get much into SPEC files, though that's where the real meat of the subject is.


Anyway, see you on FB.

Hi Chris,


    Always nice to see more  reference material from you. :)

Thanks John. As part of my job as a writer for Red Hat's customer portal, I'm always looking for holes in information to fill. If there are features in RHEL, RHEV, or other Red Hat products that need to be described better or in some specific way, let us know. If it's something I've spent some time with (like building RPMs), I can sometimes turn out a tech brief fairly quickly to fill in some knowledge gaps.

Thanks much Chris!