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.
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

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Matthew Stivala

HP OfficeJet 250 Mobile Printer

The HP OfficeJet 250 Mobile Printer is a great device that fits perfectly into my fast paced and mobile lifestyle. My first impression of the printer itself was how incredibly compact and sleek the device was.

Armand Abogado

HP OfficeJet 250 Mobile Printer

Wireless printing from my iPhone was also a handy feature, the whole experience was quick and seamless with no setup requirements - accessed through the default iOS printing menu options.

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?