Skip to Content

[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[email protected] ~] # 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

[[email protected] ~] # su - user
[[email protected] ~] $


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

[[email protected] ~] $ wget http://www.oldrpm.org/hintskins/buildtree/RPM-build-tree.txt


change the file attributes to be excusable

[[email protected] ~] $ chmod 755 RPM-build-tree.txt
[[email protected] ~] $ ./RPM-build-tree.txt
[[email protected] ~] $ 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

[[email protected] ~] $ cd rpmbuild/
[[email protected] rpmbuild] $ ls
BUILD RPMS SOURCES SPECS SRPMS
[[email protected] rpmbuild] $ cd
[[email protected] ~] $ ls
rpmbuild RPM-build-tree.txt
[[email protected] ~] $ 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

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


[[email protected] ~] # yum install ncurses-devel


Switch back to user account

[[email protected] ~] # !su
su - user
[[email protected] ~] $ cd build/
[[email protected] build] $ cd joe/


now we will start building joe rpm

[[email protected] 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

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


now we will use the root account to install the RPM

[[email protected] ~] # cd /home/user/rpmbuild/
[[email protected] rpmbuild] # cd RPMS/
[[email protected] RPMS] # ls
i386
[[email protected] RPMS] # cd i386/
[[email protected] i386] # ls
joe-2.9.8-4.i386.rpm joe-debuginfo-2.9.8-4.i386.rpm 
[[email protected] 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



Dr. Radut | book