This is a short hands-on tutorial on creating the development environment to build RPM packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL).
NOTE: The commands on this guide were tested on both CentOS 6.2 and Scientific Linux 6.2 (2.6.32-220.17.1.el6.x86_64) virtual machines.
To build RPMs we need a set of development tools. This is a one-time-only setup, installed by running those commands from a system administration (root) account.
$ su root $ <INSERT_YOUR_ROOT_PASSWORD_HERE>
Install the Extra Packages for Enterprise Linux (EPEL) repository (you may need to update the EPEL version on the following line):
# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/$(uname -m)/epel-release-6-6.noarch.rpm
Install development tools:
# yum install @development-tools
Install the fedora-packager (required to build RPM packages):
# yum install fedora-packager
Install the elfutils-devel package, it contains the libraries to create applications for handling compiled objects:
# yum install elfutils-devel
Install any additional package required by the specific program you are going to package. For example, if you need to compile modules for the kernel you need to install the kernel-devel package.
Create a dummy user specifically for creating RPM packages:
# /usr/sbin/useradd makerpm # passwd makerpm
NOTE: You should never create your packages as the root user to avoid problems in case the build process goes wrong.
Reboot the machine if you have installed any kernel module:
Login as makerpm user and create the required directory structure in your home directory by executing:
The rpmdev-setuptree program will create the ~/rpmbuild directory and a set of subdirectories (e.g. SPECS and BUILD), which you will use for creating your packages. The ~/.rpmmacros file is also created, which can be used for setting various options.
At this point the development environment is ready and you can create your RPM packages.
Create an RPM
To create an RPM package you need the source code archive of the software you want to package and the SPEC file that contains all instructions on how to configure, build and install the package.
The SPEC file must be copied on the ~/rpmbuild/SPECS directory and the source code archive must be copied on the ~/rpmbuild/SOURCES directory.
To start the building process you can use the rpmbuild command. For example:
$ cd ~/rpmbuild/SPECS $ rpmbuild -ba yourspecfile.spec
The rpmbuild command has several options, please consult the manual and official guides for more information.
After a successful building process you will find the RPM files on the ~/rpmbuild/RPMS/$(uname -m) directory.