Build your own Red Hat Packages

Build Directory

To build RPMs as local user, you need to create rpm build directory in your home directory. I recommend creating a separate user for building RPMs. To create rpm directories, issue the following command;

[rpmbuild@wfd-cos-cd1 ~]$ mkdir -p ~/mybuild/{BUILD,RPMS,SOURCE,S{PEC,RPM}S,tmp}

Macro Files

You need to create .rpmmacros file in your HOME directory

[rpmbuild@wfd-cos-cd1 ~]$ cat > $HOME/.rpmmacros << EOF
> %_topdir %(echo $HOME)/mybuild
> %_sourcedir %{_topdir}/SOURCE/%{name}-%{version}
> %_specdir %{_topdir}/SPECS
> %_tmppath %{_topdir}/tmp
> %_builddir %{_topdir}/BUILD
> %_buildroot %{_topdir}/%{_tmppath}/%{name}-%{version}-root
> %_rpmdir %{_topdir}/RPMS
> %_srcrpmdir %{_topdir}/SRPMS
> %_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm
> %packager %(echo ${USER}@)%(hostname)
> %distribution Personal Build
> EOF

You can also add %debug_package %{nil} to .rpmmacros file to avoid building the debug packages.

Also, you would need .rpmrc file in your HOME Directory

[rpmbuild@wfd-cos-cd1 ~]$ cat > $HOME/.rpmrc << EOF
> include: /usr/lib/rpm/rpmrc
> macrofiles: /usr/lib/rpm/macros:/usr/lib/rpm/%{_target}/macros:/etc/rpm/macros.specspo:/etc/rpm/macros:/etc/rpm/%{_target}/macros:~/.rpmmacros
> EOF

Sample Build

For testing the build, let us download redhat-release source rpm file

[rpmbuild@wfd-cos-cd1 ~]$ cd downloads/
[rpmbuild@wfd-cos-cd1 downloads]$ wget ftp://fr2.rpmfind.net/linux/redhat/updates/enterprise/3AS/en/os/SRPMS/redhat-release-3AS-13.6.2.src.rpm
[rpmbuild@wfd-cos-cd1 downloads]$

Install the rpm by issuing;

[rpmbuild@wfd-cos-cd1 downloads]$ rpm -i redhat-release-3AS-13.6.2.src.rpm

Above command would have created, the below files

[rpmbuild@wfd-cos-cd1 downloads]$ ls $HOME/mybuild/SOURCE/* $HOME/mybuild/SPECS
/home/rpmbuild/mybuild/SOURCE/redhat-release-3AS:
redhat-release-3AS.tar.gz
/home/rpmbuild/mybuild/SPECS:
redhat-release.spec
[rpmbuild@wfd-cos-cd1 downloads]$

Use rpmbuild command to test building binary RPM

[rpmbuild@wfd-cos-cd1 downloads]$ rpmbuild -ba $HOME/mybuild/SPECS/redhat-release.spec
Executing(%prep): /bin/sh -e /home/rpmbuild/mybuild/tmp/rpm-tmp.72442
+ umask 022
+ cd /home/rpmbuild/mybuild/BUILD
+ cd /home/rpmbuild/mybuild/BUILD
+ rm -rf redhat-release-3AS
+ /bin/gzip -dc /home/rpmbuild/mybuild/SOURCE/redhat-release-3AS/redhat-release-3AS.tar.gz
......
......
......
Wrote: /home/rpmbuild/mybuild/SRPMS/redhat-release-3AS-13.6.2.src.rpm
Wrote: /home/rpmbuild/mybuild/RPMS/redhat-release-3AS-13.6.2.i386.rpm
Executing(%clean): /bin/sh -e /home/rpmbuild/mybuild/tmp/rpm-tmp.695
+ umask 022
+ cd /home/rpmbuild/mybuild/BUILD
+ cd redhat-release-3AS
+ rm -rf /home/rpmbuild/mybuild/tmp/redhat-release-root
+ exit 0
[rpmbuild@wfd-cos-cd1 downloads]$

If you see exit 0, then the binay RPM has been built successfully, newly built RPM should be available under $HOME/mybuild/RPMS and $HOME/mybuild/SRPMS

Leave a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.