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 PC World newsletter!

Error: Please check your email address.

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World
Show Comments


Lexar® JumpDrive® S57 USB 3.0 flash drive

Learn more >

Microsoft L5V-00027 Sculpt Ergonomic Keyboard Desktop

Learn more >


Lexar® JumpDrive® S45 USB 3.0 flash drive 

Learn more >


Lexar® Professional 1800x microSDHC™/microSDXC™ UHS-II cards 

Learn more >

HD Pan/Tilt Wi-Fi Camera with Night Vision NC450

Learn more >

Lexar® JumpDrive® C20c USB Type-C flash drive 

Learn more >

Audio-Technica ATH-ANC70 Noise Cancelling Headphones

Learn more >


Back To Business Guide

Click for more ›

Most Popular Reviews

Latest News Articles


GGG Evaluation Team

Kathy Cassidy


First impression on unpacking the Q702 test unit was the solid feel and clean, minimalist styling.

Anthony Grifoni


For work use, Microsoft Word and Excel programs pre-installed on the device are adequate for preparing short documents.

Steph Mundell


The Fujitsu LifeBook UH574 allowed for great mobility without being obnoxiously heavy or clunky. Its twelve hours of battery life did not disappoint.

Andrew Mitsi


The screen was particularly good. It is bright and visible from most angles, however heat is an issue, particularly around the Windows button on the front, and on the back where the battery housing is located.

Simon Harriott


My first impression after unboxing the Q702 is that it is a nice looking unit. Styling is somewhat minimalist but very effective. The tablet part, once detached, has a nice weight, and no buttons or switches are located in awkward or intrusive positions.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?