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!


Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World
Show Comments

Cool Tech

Toys for Boys

Family Friendly

Stocking Stuffer

SmartLens - Clip on Phone Camera Lens Set of 3

Learn more >

Christmas Gift Guide

Click for more ›

Brand Post

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Aysha Strobbe

Microsoft Office 365/HP Spectre x360

Microsoft Office continues to make a student’s life that little bit easier by offering reliable, easy to use, time-saving functionality, while continuing to develop new features that further enhance what is already a formidable collection of applications

Michael Hargreaves

Microsoft Office 365/Dell XPS 15 2-in-1

I’d recommend a Dell XPS 15 2-in-1 and the new Windows 10 to anyone who needs to get serious work done (before you kick back on your couch with your favourite Netflix show.)

Maryellen Rose George

Brother PT-P750W

It’s useful for office tasks as well as pragmatic labelling of equipment and storage – just don’t get too excited and label everything in sight!

Cathy Giles

Brother MFC-L8900CDW

The Brother MFC-L8900CDW is an absolute stand out. I struggle to fault it.

Luke Hill


I need power and lots of it. As a Front End Web developer anything less just won’t cut it which is why the MSI GT75 is an outstanding laptop for me. It’s a sleek and futuristic looking, high quality, beast that has a touch of sci-fi flare about it.

Emily Tyson

MSI GE63 Raider

If you’re looking to invest in your next work horse laptop for work or home use, you can’t go wrong with the MSI GE63.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?