Posted: 23 Mar 2005
"The RPM Package Manager (RPM) is a powerful command line driven package management
system capable of installing, uninstalling, verifying, querying, and updating
computer software packages."1
RPM is now considered the 'standard' for application and system packaging by
most Linux distributions. Novell SUSE LINUX is one of those distributions that
has standardized on RPM.
The design goals for RPM are to:
- make it easy to get packages on and off the system
- make it easy to verify that a package was installed correctly
- make it easy for the package builder
- make the build process start with the original source code
- make it work on different computer architectures
There are many "How-to's" and tutorials describing how to create RPMs (see
Resources). However, creating RPMs in a clean build environment and in a
consistent reproducible way, requires more effort than should be necessary.
Novell SUSE LINUX provides a utility called build that streamlines the RPM
creation process and ensures configuration and system uniformity. It does this
in an isolated chroot environment containing only the required packages
necessary to create your RPM.
This tutorial describes how to use the build utility to easily create RPMs
for Novell SUSE LINUX.
Where to Begin
To use build you must first install build.rpm. The build.rpm package is
available via YaST or from Novell SUSE LINUX's download site (see Resources for
The build.rpm package includes the following files:
In addition to the “/usr/bin/build” utility, build.rpm contains a useful
RPM-related command called “/usr/bin/unrpm.” The unrpm command is a simple
script to “expand” the contents of an RPM in the current directory (using
Once you have installed build.rpm you will need either to mount a Novell SUSE
LINUX DVD (or DVD ISO image) or create a directory containing the contents of
the DVD. If you only have CDs, then copy all of the contents of the CDs into a
Creating a local directory containing the contents of the DVD is highly
recommended since it is far easier to update RPMs in a local directory than it
is on a DVD:)
To create such a directory, copy everything under the DVD's top level
directory using the following command:
cp -a /media/dvd/*
The RPMs are used to create a reproducible build environment. The DVD or the
directory containing the RPMs must also include any additional RPMs needed to
satisfy your packages' build requirements that are not part of a standard Novell
SUSE LINUX release.
By default, the RPMs are assumed to be located on a DVD that is mounted in
the following directory:
To override this default location, you need to set an environment variable
named BUILD_RPMS to point to the directory containing the RPMs. Another way to
specify where the RPMs are located is by using the --rpms option when invoking
the build command.
build –rpms /work/9.2
How to Use the build Utility
To use build you must be root (root is required to use the chroot command).
The chroot environment, by default, is created in the following location:
The build utility takes as an argument an RPM spec file or a source RPM file
(if no argument is specified, build assumes that the current directory contains
a spec file and a source tar ball). If an RPM spec file is specified, a tar ball
containing the source files is expected to be in the current directory. For
those new to RPMs and RPM spec files, please look at the references at the end
of this tutorial.
The key to creating an RPM spec file that build can use is to add one extra
tag to the spec file. The special tag is BuildRequires, which lists all of the
RPMs that are required to be installed in order for the source package to
The build command initializes the build environment by installing all of the
required packages necessary to compile the given RPM package. build then copies
all of the source files, patch files and the rpm spec file into the chroot build
area. The new build area becomes the "new" root in which build will operate.
The successful result of executing build is a binary RPM (a repackage source
rpm is also generated) created in:
Enabling your application to be built using build ensures a reproducible
build environment that doesn't get corrupted by the host's environment and
To test your newly created RPM, simply chroot into the build environment and
install your RPM package using the standard rpm command.
Example Using build
A simple way to see how to use the build utility is to use build to create
the GNU hello world RPM binary package.
- Get the appropriate hello--.src.rpm (for the purposes of
this example I will use hello-2.1.1-311.src.rpm) by downloading it from the
source directory for the Novell SUSE LINUX version (e.g. 9.1, 9.2, SLES9,
NLD9) you are using for RPMs referenced by build.rpm.
- Create a directory called hello and change into it:
mkdir hello cd
- Use the unrpm command to look at the contents of the source RPM:
- The directory will now contain the following files:
hello-2.1.1-311.src.rpm hello-2.1.1.tar.gz hello.spec
- If you look in the hello.spec file you will see the BuildRequires tag that
build.rpm uses to install all specified RPMs into a build
aaa_base acl attr bash bind-utils bison bzip2 coreutils cpio cppcracklib cvs
cyrus-sasl db devs diffutils e2fsprogs file filesystem fillup findutils flex
gawk gdbm-devel glibc glibc-devel glibc-locale gpm grep groff gzip info
insserv less libacl libattr libgcc libnscd libselinux libstdc++ libxcrypt
libzio m4 make man mktemp module-init-tools ncurses ncurses-devel net-tools
netcfg openldap2-client openssl pam pam-modules patch permissions popt
procinfo procps psmisc pwdutils rcs readline sed strace syslogd sysvinit tar
tcpd texinfo timezone unzip util-linux vim zlib zlib-devel autoconf automake
binutils gcc gdbm gettext libtool perl rpm ...
- Now switch user to root (su command)
- Issue the following command:
- The build command will create, by default, an isolated build environment
- If all goes well you will see the following message after build has
/bin/sh -e /var/tmp/rpm-tmp.2137
+ umask 022
+ cd hello-2.1.1
/var/tmp/hello-2.1.1-build '!=' / ']'
+ '[' -d /var/tmp/hello-2.1.1-build
+ rm -rf /var/tmp/hello-2.1.1-build
+ exit 0
- The created binary and source RPMs are found in:
- If you want to check the installation of your binary RPM you can chroot
into the build area and use the rpm command:
The RPM should install without any issues.
This tutorial has given a brief overview of Novell SUSE LINUX's build
utility. Please consult the build man page for addition information and a
description of other beneficial command line options.
Using build.rpm is an easy and reproducible way to create binary and source
RPMs for Novell SUSE LINUX in an isolated build environment. As a side benefit,
the isolated environment can also be used to test the installation of your
The build.rpm utility can also be used to create RPMs for multiple versions
of Novell SUSE LINUX on a single system. How to do this is the topic of another
tutorial on build.rpm.