[Howto] How to Build RPMs without root access ?

Hello,
In this Howto we will represent a simple trick to building an RPM without having root access. You can build it in your home directory.


We will see how to create the RPM build directories and how to setup your ~/.rpmmacros
The .rpmmacros file is used by rpmbuild to provide defaults. You may find references to the .rpmrc file, but it has been deprecated in favor of this file.
we need also to create build directories. By default, rpm will expect to find and use the following directories:


%{_topdir}/BUILD
%{_topdir}/RPMS
%{_topdir}/RPMS/i386
%{_topdir}/SOURCES
%{_topdir}/SPECS
%{_topdir}/SRPMS


I will not do this manually i will use herrold script ;)
Let's start...
First We need to set the enviroment needs for building software essential developing tools


[root@localhost ~] # yum -y install rpm-build make m4 gcc-c++ autoconf automake redhat-rpm-config


after the installation completed we need to move to normal user


[root@localhost ~] # su - user
[user@localhost ~] $


now we will setup a non-root user build environment under home dir


[user@localhost ~] $ wget http://www.oldrpm.org/hintskins/buildtree/RPM-build-tree.txt


change the file attributes to be excusable


[user@localhost ~] $ chmod 755 RPM-build-tree.txt
[user@localhost ~] $ ./RPM-build-tree.txt
[user@localhost ~] $ ls -ali
total 80
1342179 drwx------ user user 4096 Feb 13 11:43 .
1342177 drwxr-xr-x user user 4096 Feb 13 11:22 ..
1342183 -rw------- user user   22 Feb 13 11:26 .bash_history
1342180 -rw-r--r-- user user   33 Feb 13 11:22 .bash_logout
1342182 -rw-r--r-- user user  176 Feb 13 11:22 .bash_profile
1342181 -rw-r--r-- user user  124 Feb 13 11:22 .bashrc
1342187 drwxr-xr-x user user 4096 Feb 13 11:43 rpmbuild
1342185 -rwxrwxrwx user user 2117 Dec 16  2006 RPM-build-tree.txt
1342186 -rw-rw-r-- user user   49 Feb 13 11:43 .rpmmacros

[user@localhost ~] $ cd rpmbuild/
[user@localhost rpmbuild] $ ls
BUILD RPMS SOURCES SPECS SRPMS
[user@localhost rpmbuild] $ cd
[user@localhost ~] $ ls
rpmbuild RPM-build-tree.txt
[user@localhost ~] $ rpm --showrc | grep topdir
-14 _builddir    %{_topdir}/BUILD
-14 _rpmdir      %{_topdir}/RPMS
-14 _sourcedir   %{_topdir}/SOURCES
-14 _specdir     %{_topdir}/SPECS
-14 _srcrpmdir   %{_topdir}/SRPMS
-14 _topdir      /home/user/rpmbuild


Now We will go in this sequence 1- Move to the home directory 2- Make the ~/build/ subdirectory 3- Move into ~/build/ subdirectory 4- Make the ~/build/joe/ subdirectory 5- Move into ~/build/joe/ subdirectory 6- Update our notes in the README 7- Retrieve the SRPM using get 8- Build the binary RPM


[user@localhost ~] $ mkdir build
[user@localhost ~] $ cd build/
[user@localhost build] $ mkdir joe
[user@localhost build] $ cd joe/
[user@localhost joe] $ nano README
[user@localhost joe] $ wget ftp://ftp.owlriver.com/pub/mirror/ORC/joe/joe-2.9.8-4.src.rpm
[user@localhost joe] $ rpmbuild --rebuild joe-2.9.8-4.src.rpm
[user@localhost joe] $ exit



[root@localhost ~] # yum install ncurses-devel


Switch back to user account


[root@localhost ~] # !su
su - user
[user@localhost ~] $ cd build/
[user@localhost build] $ cd joe/


now we will start building joe rpm


[user@localhost joe] $ rpmbuild --rebuild joe-2.9.8-4.src.rpm

after the compiling finished you will find joe rpm in /home/user/rpmbuild/RPMS/i386


[user@localhost joe] $ cd
[user@localhost ~] $ cd rpmbuild/
[user@localhost rpmbuild] $ ls 
BUILD RPMS SOURCES SPECS SRPMS
[user@localhost rpmbuild] $ cd RPMS/
[user@localhost RPMS] $ ls 
i386
[user@localhost RPMS] $ cd i386
[user@localhost i386] $ ls 
joe-2.9.8-4.i386.rpm joe-debuginfo-2.9.8-4.i386.rpm 
[user@localhost i386] $ rpm -qi joe-2.9.8-4.i386.rpm
package joe-2.9.8-4.i386.rpm is not installed
[user@localhost i386] $ exit


now we will use the root account to install the RPM


[root@localhost ~] # cd /home/user/rpmbuild/
[root@localhost rpmbuild] # cd RPMS/
[root@localhost RPMS] # ls
i386
[root@localhost RPMS] # cd i386/
[root@localhost i386] # ls
joe-2.9.8-4.i386.rpm joe-debuginfo-2.9.8-4.i386.rpm 
[root@localhost i386] # rpm -Uvh joe-2.9.8-4.i386.rpm


-U option is updating the package, and install it if it's not installed

DONE