In this post I will build a very simple RPM, this RPM will contain a very useful program/shell script.
With this information you can build complex RPMs later on.

Set up your build environment

In this case I am using a RHEL 6.5 64bit system

Install the tools:
rpm-build: is what you need to build RPMs
rpmdevtools: is not required but it is very helpful because it helps you create the directory tree and base SPEC file

Create a non-privileged user to build the RPMs

Create the directory tree using rpmdev-setuptree

Package Application

Work on packaging your application/program (e.g.
The folder and the archive naming is important for later when they get unarchived, the rpm tools will by default use name-version (e.g. name=very-useful-script, version=1.0, that is why the folder/archive was named very-useful-script-1.0/ ).
That is the default and can be easily changed in the SPEC file.

Move your packaged application to the SOURCES directory under rpmbuild/

Now it is time to create the SPEC

Create a skeleton spec file

Move it to your directory tree

This is how your directory tree should look like

SPEC file:

Dissecting the SPEC file
The below is header information and just descriptive data

The below is where we prepare our sources to be packaged into RPM
%prep is a section where we can execute commands or use macros.
%setup is a macro that unarchives the original sources.
Earlier I was discussing the importance of naming the folder and archive as name-version, this is because the %setup macro expects that by default, but you can overwrite the default by specifying the folder name (e.g. %setup -q -n very-useful-script-1.0-john-x86)


The below removes previous remains of the files in the buildroot
Then creates a folder /usr/local/bin/ in the buildroot
Then puts our in /usr/loca/bin with mode 755

The below just cleans the buildroot

The below specifies all the files that will be installed by the RPM
You need to list them all, or use wildcards

Build the RPM using the SPEC file

After the RPM has been successfully been built, you can find it under:

Install it (need to be root)

Hopefully this guide will help you when building RPMs.