Tips and Tricks: Building rpms without being root
by the editorial team
Contributed by Jesus Rodriguez
I got tired of having to become root to install a src.rpm and to build it. Turns out a little magic in $HOME/.rpmmacros will do the trick.
Do the following:
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo “%home %(echo $HOME)” >> $HOME/.rpmmacros
echo “%_topdir %{home}/rpmbuild” >> $HOME/.rpmmacros
Now when you install a src.rpm it will go to $HOME/rpmbuild/ instead of /usr/src/redhat/.
That’s it.







June 5th, 2007 at 8:42 am
You can do the same thing by running the ‘rpmdev-setuptree’ command from the rpmdevtools package.
June 6th, 2007 at 10:11 am
Thank you Jesus!
June 6th, 2007 at 9:25 pm
rpmdevtools works in fedora, but in RHEL4 where I first used the tip, I didn’t have rpmdevtools. Good to know that it’s automated.
June 7th, 2007 at 5:07 pm
Shouldn’t this:
echo “%home %(echo $HOME)” >> $HOME/.rpmmacros
be changed to this?:
echo “%home $(echo $HOME)” >> $HOME/.rpmmacros
June 8th, 2007 at 7:09 pm
Hi Bill
You are correct, that should be a $
You can also compile rpms as user by adding the following subdirs:
%{_topdir}/BUILD
%{_topdir}/RPMS
%{_topdir}/RPMS/i386
%{_topdir}/SOURCES
%{_topdir}/SPECS
%{_topdir}/SRPMS
Of course under RPMS directory, there should be a subdirectory for every arch you need to support.
June 10th, 2007 at 8:59 pm
In Fedora 7
[jerry@server1 ~]$ mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
[jerry@server1 ~]$ echo “%home %(echo $HOME)” >> $HOME/.rpmmacros
bash: syntax error near unexpected token `(’
[jerry@server1 ~]$ echo ‘%home %(echo $HOME)’ >> $HOME/.rpmmacros
[jerry@server1 ~]$ echo “%_topdir %{home}/rpmbuild” >> $HOME/.rpmmacros
June 13th, 2007 at 11:45 am
My variant on the static:
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
which doesn’t provide the needed arch directories.
I don’t have rpmtools installed, but it’s easy for me to create the needed rpmbuild tree by doing this:
(cd /usr/src/redhat && \
find * -type d -exec mkdir -vp $HOME/rpmbuild/{} \; )
That way I always get a tree just line the “official” one installed with the distro. Works for RedHat and Fedora.
August 19th, 2008 at 12:09 pm
Ignore comment #4. It should be a % and not a $. That is, it is: echo “%home %(echo $HOME)” >> $HOME/.rpmmacros