How RPM packages are made: the source RPM

In a previous post, we looked at what RPM packages are. They are archives that contain files and metadata. This metadata tells RPM where to create or remove files from when an RPM is installed or uninstalled. The metadata also contains information on “dependencies”, which you will remember from the previous post, can either be “runtime” or “build time”.

As an example, we will look at fpaste. You can download the RPM using dnf. This will download the latest version of fpaste that is available in the Fedora repositories. On Fedora 30, this is currently

$ dnf download fpaste


Since this is the built RPM, it contains only files needed to use fpaste:

$ rpm -qpl ./fpaste-

Source RPMs

The next link in the chain is the source RPM. All software in Fedora must be built from its source code. We do not include pre-built binaries. So, for an RPM file to be made, RPM (the tool) needs to be:

  • given the files that have to be installed,
  • told how to generate these files, if they are to be compiled, for example,
  • told where these files must be installed,
  • what other dependencies this particular software needs to work properly.

The source RPM holds all of this information. Source RPMs are similar archives to RPM, but as the name suggests, instead of holding the built binary files, they contain the source files for a piece of software. Let’s download the source RPM for fpaste:

$ dnf download fpaste --source

Notice how the file ends with “src.rpm”. All RPMs are built from source RPMs. You can easily check what source RPM a “binary” RPM comes from using dnf too:

$ dnf repoquery --qf "%{SOURCERPM}" fpaste

Also, since this is the source RPM, it does not contain built files. Instead, it contains the sources and instructions on how to build the RPM from them:

$ rpm -qpl ./fpaste-

Here, the first file is simply the source code for fpaste. The second is the “spec” file. The spec file is the recipe that tells RPM (the tool) how to create the RPM (the archive) using the sources contained in the source RPM—all the information that RPM (the tool) needs to build RPMs (the archives) are contained in spec files. When we package maintainers add software to Fedora, most of our time is spent writing and perfecting the individual spec files. When a software package needs an update, we go back and tweak the spec file. You can see the spec files for ALL packages in Fedora at our source repository at

Note that one source RPM may contain the instructions to build multiple RPMs. fpaste is a very simple piece of software, where one source RPM generates one “binary” RPM. Python, on the other hand is more complex. While there is only one source RPM, it generates multiple binary RPMs:

$ sudo dnf repoquery --qf "%{SOURCERPM}" python3

$ sudo dnf repoquery --qf "%{SOURCERPM}" python3-devel

$ sudo dnf repoquery --qf "%{SOURCERPM}" python3-libs

$ sudo dnf repoquery --qf "%{SOURCERPM}" python3-idle

$ sudo dnf repoquery --qf "%{SOURCERPM}" python3-tkinter

In RPM jargon, “python3” is the “main package”, and so the spec file will be called “python3.spec”. All the other packages are “sub-packages”. You can download the source RPM for python3 and see what’s in it too. (Hint: patches are also part of the source code):

$ dnf download --source python3

$ rpm -qpl ./python3-3.7.4-1.fc30.src.rpm

Building an RPM from a source RPM

Now that we have the source RPM, and know what’s in it, we can rebuild our RPM from it. Before we do so, though, we should set our system up to build RPMs. First, we install the required tools:

$ sudo dnf install fedora-packager

This will install the rpmbuild tool. rpmbuild requires a default layout so that it knows where each required component of the source rpm is. Let’s see what they are:

# Where should the spec file go?
$ rpm -E %{_specdir}

# Where should the sources go?
$ rpm -E %{_sourcedir}

# Where is temporary build directory?
$ rpm -E %{_builddir}

# Where is the buildroot?
$ rpm -E %{_buildrootdir}

# Where will the source rpms be?
$ rpm -E %{_srcrpmdir}

# Where will the built rpms be?
$ rpm -E %{_rpmdir}

I have all of this set up on my system already:

$ cd
$ tree -L 1 rpmbuild/
├── RPMS

6 directories, 0 files

RPM provides a tool that sets it all up for you too:

$ rpmdev-setuptree

Then we ensure that we have all the build dependencies for fpaste installed:

sudo dnf builddep fpaste-

For fpaste you only need Python and that must already be installed on your system (dnf uses Python too). The builddep command can also be given a spec file instead of an source RPM. Read more in the man page:

$ man dnf.plugin.builddep

Now that we have all that we need, building an RPM from a source RPM is as simple as:

$ rpmbuild --rebuild fpaste-

$ tree ~/rpmbuild/RPMS/noarch/
└── fpaste-

0 directories, 1 file

rpmbuild will install the source RPM and build your RPM from it. You can now install the RPM to use it as you do–using dnf. Of course, as said before, if you want to change anything in the RPM, you must modify the spec file—we’ll cover spec files in next post.


To summarise this post in two short points:

  • the RPMs we generally install to use software are “binary” RPMs that contain built versions of the software
  • these are built from source RPMs that include the source code and the spec file that are needed to generate the binary RPMs.

If you’d like to get started with building RPMs, and help the Fedora community maintain the massive amount of software we provide, you can start here:

For any queries, post to the Fedora developers mailing list—we’re always happy to help!

Fedora Project community


  1. The banner image makes me so happy… that’s the Stadtbibliothek Stuttgart!
    Lovely. Thanks.
    Great article, by the way.

  2. Kees de Jong


  3. tr

    brew are easy,
    meybe in future somebody wrote converter brew ruby prog to rpm

  4. MX

    man mock

  5. Leandro

    Great article! Thanks!!

  6. Adam Miller

    Here’s a comprehensive intro packaging guide if anyone is interested.

  7. leslie Satenstein

    Hi Ankur
    Thank you for this and the provious articles. I have a favour to ask.

    Is there any chance that you can put the previous articles and this one together as a downloadable PDF file. Your expository is most informative. I do like
    “under-the-cover” articles explaining important features of package management.
    I tried with cut/paste to Libreoffice, but sections of the pasted output have very unappealing results within LibreOffice’s writer program.

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions