RPM Building Crash Course

By Pierre Sarrazin
May 9th, 2007.

(See French version.)

Getting the rpmbuild command

Your system may currently have the rpm command but not the rpmbuild command. (If the command "which rpmbuild" does not display anything, you don't have rpmbuild.) On Red Hat and Fedora systems, the rpmbuild command is provided by the rpm-build RPM package. (You can give the command "rpm -q rpm-build" to check if it is installed.)

Avoiding root

By default, RPM packages are built in the /usr/src/redhat directory, which is only writable by root. You can have the rpmbuild command use another directory (e.g., /home/your_userid/rpm) by putting this line in a file called .rpmmacros in your home directory:

%_topdir /home/your_userid/rpm

You must then create the following subdirectories in that directory:

cd /home/your_userid/rpm
mkdir -p RPMS/i386 RPMS/athlon RPMS/i486 RPMS/i586 RPMS/i686 RPMS/noarch

See the RPM reference documentation for details.

Building from a source RPM (SRPM)

Install the .src.rpm file this way:

rpm -i somepackage-1.0-1.src.rpm

This will create files in the SOURCES directory of your RPM building directory tree, and a .spec file in the SPECS directory.

Then go the SPECS directory and give the command to build the RPM:

cd /home/your_userid/rpm/SPECS
rpmbuild -bb somepackage.spec

Give the -ba option instead if you also want to build the SRPM. The binary RPM packages will typically be created in the RPMS/i386 directory (on a PC-based system).

Building from a source archive

When a source archive (e.g., somepackage-1.0.tar.gz) contains a .spec file, one can give the following command to build the RPM without having to deploy the archive:

rpmbuild -tb somepackage-1.0.tar.gz

Give the -ta option instead if you also want to build the SRPM.

(The source archives that I publish are supposed to contain a functional .spec file. If I omitted this, please complain to me.)

Further Reading