Building RPM packages

RPM’s are Redhat packages for installing software on Redhat Linux machines. Creating the RPMs is done by the software owner.

Building RPM should be done with an unprivileged user and NOT root !
Setting up a build environment

To be able to build under a normal user account you need to set it up once on your build/development host.

First you will need to create the Directory structure by running the following command:

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

 

After that you will have to create the ~/.rpmmacros file with the following content:

%_signature gpg
%_gpg_name  <YOURNAME>
%packager <YOUR_E_MAIL>
%_topdir           %(echo $HOME)/rpmbuild
%_builddir          %{_topdir}/BUILD
%_rpmdir           %{_topdir}/RPMS
%_sourcedir         %{_topdir}/SOURCES
%_specdir           %{_topdir}/SPECS
%_srcrpmdir         %{_topdir}/SRPMS
%_buildrootdir      %{_topdir}/BUILDROOT

Don’t forget to replace <YOURNAME> and <YOUR_E_MAIL> with the appropriate values.

Installing source RPM’s

If your build environment is set up correctly you can install source RPM’s as a normal user with the following command:

rpm -ivh <filename.src.rpm>
Building RPM’s

You can edit/create your SPEC file ~/rpmbuild/SPECS/<filename.spec> and edit/add SOURCE files in ~/rpmbuild/SOURCES/

The new RPM can be created by running the following command:

rpmbuild -ba ~/rpmbuild/SPECS/<filename.spec>

The new RPM files will be written to ~/rpmbuild/RPMS/<arch> and your new source RPM’s will be written to ~/rpmbuild/SRPMS/

 

Needed Packages

To build rpm packages on RedHat you need al least the following packages to be installed :

rpm-build 
redhat-rpm-config
gcc
kernel-headers-`uname -r`
kernel-devel-`uname -r`