Compiling software with Rpmbuild

The performance and space-saving advantages of compiling software from source are regularly championed in this column. Many users, however, find it much easier to install pre-compiled applications distributed in the RPM or DEB formats. In this column, we instruct you in using a tool that combines the performance advantages of compiling software from source with the ease of installation offered by pre-compiled binaries.

Have you ever downloaded a Linux application from the Internet and noticed files of the type .src.rpm as available downloads? These files are called source RPMs and contain the source code to the application, as well as instructions on how to turn it into a binary RPM. The rpmbuild tool can use these instructions, known as a spec file, to automatically compile the application and produce a binary RPM for you.

Any distribution based on RPM should already have rpmbuild installed. You can check this by typing into a shell:

$ rpmbuild

which will display if rpmbuild is installed:

rpmbuild: no spec files given for build

To compile a .src.rpm with rpmbuild, use the --rebuild flag as shown below. You may need to be the root user to build an RPM with rpmbuild. To compile a large application with rpmbuild you will potentially need a large amount of free disk space, up to 1GB, available under /usr/src. Note that compiling a large application with rpmbuild may take up to a couple of hours, depending on your CPU speed.

$ rpmbuild --rebuild program.src.rpm

The process of compiling the application and building an RPM is entirely automated from start to finish and will be displayed on the screen. Often when rebuilding a .src.rpm, you will encounter what is known as a missing dependency. These usually take the form of a missing system file. To compile a .src.rpm, many development packages, identifiable by the presence of the string ‘-devel’ in the filename, may be required. To list the dependencies of a .src.rpm, type the following in a shell:

$ rpm -qp --requires program.src.rpm

Before attempting to rebuild a .src.rpm, first verify that all of these dependencies have been installed. At the conclusion of the rpmbuild process the location of the freshly compiled binary RPMs generated by rpmbuild will be displayed. Under Red Hat Linux, this location is /usr/src/redhat/. Often two or more RPMs will be generated from a single .src.rpm file. You can install these RPMs as you would any other, by typing as root: $ rpm -ivh program.rpm


The key advantage of compiling software is the optimisations, which can be used to improve performance and reduce space requirements. Rpmbuild can be used to optimise RPMs for your CPU, potentially significantly increasing the performance of your Linux system. To use optimisations when building a .src.rpm, add the --target= flag to the rpmbuild command. For example, to optimise a .src.rpm for an AMD Athlon CPU use the following command:

$ rpmbuild --rebuild --target=athlon program.src.rpm

Pentium II/III/IV owners should change ‘athlon’ to ‘i686’.

Optimisation flags for each architecture are stored in the file /usr/lib/rpm/rpmrc. You can modify the default optimisations by editing this file or, if you wish to use different optimisation flags for individual users, by making a copy of this file named ~/.rpmrc. The section of the rpmrc file concerned with optimisations is structured as follows:


For example, the default optimisation flags for an AMD Athlon CPU are:

optflags: athlon -O2 -march=athlon

Users experienced with compiler optimisations should replace the default optimisation flags with their own. GCC offers many optimisation flags that can significantly improve the performance of applications. A more aggressive set of optimisations for an AMD Athlon or Intel Pentium IV is as follows:

optflags: i686 -O3 -march=i686 -fomit-frame-pointer -mcpu=pentium4 optflags: athlon -O3 -march=athlon -fomit-frame-pointer

These optimisations should safely compile almost all RPMs. If you encounter problems compiling or running a program compiled with these optimisations, try reverting to the default optimisations for your CPU. Aggressive optimisation can sometimes result in instability and errors in applications.

Where to start

Most distributions include a number of source CDs alongside their installation CDs. These source CDs include .src.rpm files of identical versions of the applications installed with the distribution. To start experimenting with rpmbuild, try rebuilding an application you regularly use that is included on these CDs. On my system I have rebuilt Evolution, XFree86 and many components of both KDE and GNOME. Often the performance increases are very noticeable and worth the extra time and effort involved.

Join the newsletter!

Error: Please check your email address.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World
Show Comments



Sansai 6-Outlet Power Board + 4-Port USB Charging Station

Learn more >



Back To Business Guide

Click for more ›

Brand Post

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Louise Coady

Brother MFC-L9570CDW Multifunction Printer

The printer was convenient, produced clear and vibrant images and was very easy to use

Edwina Hargreaves

WD My Cloud Home

I would recommend this device for families and small businesses who want one safe place to store all their important digital content and a way to easily share it with friends, family, business partners, or customers.

Walid Mikhael

Brother QL-820NWB Professional Label Printer

It’s easy to set up, it’s compact and quiet when printing and to top if off, the print quality is excellent. This is hands down the best printer I’ve used for printing labels.

Ben Ramsden

Sharp PN-40TC1 Huddle Board

Brainstorming, innovation, problem solving, and negotiation have all become much more productive and valuable if people can easily collaborate in real time with minimal friction.

Sarah Ieroianni

Brother QL-820NWB Professional Label Printer

The print quality also does not disappoint, it’s clear, bold, doesn’t smudge and the text is perfectly sized.

Ratchada Dunn

Sharp PN-40TC1 Huddle Board

The Huddle Board’s built in program; Sharp Touch Viewing software allows us to easily manipulate and edit our documents (jpegs and PDFs) all at the same time on the dashboard.

Featured Content

Product Launch Showcase

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?