Build an RPM

We’re going to build a simple RPM that is just going to extract a tarball to /opt/motorrobot.

Install the rpmbuild package

yum -y install rpm-build

Put tarball in /root/rpmbuild/SOURCES
The default place for redhat packages to be built is under /root/rpmbuild, you will see BUILD, BUILDROOT, RPMS, SOURCES, SPECS and SRPMS.

Here we will create a directory, example file, and tar it up, this will be the SOURCE tarball for the RPM.

cd /root/rpmbuild/SOURCES && mkdir motorrobot-0.77 && echo "test file contents" >> motorrobot-0.77/motorrobot-example-file && tarcfz motorrobot.tar.gz motorrobot-0.77 && rm -rf motorrobot-0.77

Create the spec file in /root/rpmbuild/SPECS/

vi /root/rpmbuild/SPECS/motorrobot.spec
Name: motorrobot
Version: 0.77
Release: 0
Summary: RPM HowTo Example
License: GPL
Vendor: AJC
Group: System Environment/Base
Source0: %{name}.tar.gz
BuildArch: i386
Obsoletes: motorrobot < %{version}
This package extracts a tarball motorrobot.tar.gz (put in sources) into a folder /opt/motorrobot
%setup -q motorrobot
mkdir -p $RPM_BUILD_ROOT/opt/motorrobot
cp -R * $RPM_BUILD_ROOT/opt/motorrobot/
* Mon Sep 10 2012 <info@motorrobot>
- Creating the first revision of example RPM

Now lets build the RPM

rpmbuild -ba /root/rpmbuild/SPECS/motorrobot.spec

At the end you should see some output like

Processing files: motorrobot-0.77-0.i386
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(VersionedDependencies) <= 3.0.3-1
Obsoletes: motorrobot < 0.77
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/motorrobot-0.77-0.i386
Wrote: /root/rpmbuild/RPMS/i386/motorrobot-0.77-0.i386.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.RUf3Bd
umask 022
cd /root/rpmbuild/BUILD
cd motorrobot-0.77
rm -rf /root/rpmbuild/BUILDROOT/motorrobot-0.77-0.i386
exit 0

Specifically we see

Wrote: /root/rpmbuild/RPMS/i386/motorrobot-0.77-0.i386.rpm