Working with source RPMs

There's a very good page at CentOS summarizing the use of RPMs and Yum at Yum and RPM Tricks

One of the wisest things to do is not build packages as root. Instead, use an ordinary user account. While you usually don't any problem using root, one day this will save some system.

There are fundamentally two kinds of rpms: binary rpms and source rpms. The kind that let you fix real problems are source rpms.

Gettting started

First, you need the "rpm-build" package: yum install rpm-build.

Second, you probably want the "rpmdevtools" package: yum install rpmdevtools. (Not really necessary, but occcasionally convenient.)

Finally, and most importantly, create this file and these directories:

$ cat > ~/.rpmmacros
%_topdir            /home/langley/rpmbuild
$ mkdir ~/rpmbuild ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS,BUILDROOT}

The easiest of the easy

Fortunately, the most common problem that is solved by rebuilding an rpm is when you have a shared library conflict. Generally, some binary rpm has been built with a library version that you don't have and cannot conveniently install.

So find the source rpm. For Fedora 15, for instance, you can go here.

Put it the source rpm in ~/SRPMS. Then just use rpmbuild --rebuild. This will rebuild using your current shared libraries, and will usually solve your problem. You will find the result in ~/RPMS/SOMEARCH

When you want more features

Sometimes, you want to have an additional feature, such as postgresql support for postfix. To do this, you need to disassemble the rpm, change your bits, and reassemble the rpm.

First, use "rpm2cpio" to extract the contents of the source rpm in ~/rpmbuild/SOURCES: rpm2cpio SOMESRPM | cpio -i -d

Next, move the spec file to ~/SPECS and edit it: mv SOMESRPM.spec ~/rpmbuild/SPECS ; cd ~/rpmbuild/SPECS; edit ./SOMERPM.spec

Finally, rebuild with rpmbuild: rpmbuild -ba SOMESRPM.spec

If all goes well, you will, like previously, have your new rpm ready to go in ~/RPMS/SOMEARCH.