Rate this page del.icio.us  Digg slashdot StumbleUpon

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.

The information provided in this article is for your information only. The origin of this information may be internal or external to Red Hat. While Red Hat attempts to verify the validity of this information before it is posted, Red Hat makes no express or implied claims to its validity.

8 responses to “Tips and Tricks: Building rpms without being root”

  1. Anonymous says:

    You can do the same thing by running the ‘rpmdev-setuptree’ command from the rpmdevtools package.

  2. Jason O'Connell says:

    Thank you Jesus!

  3. Jesus M. Rodriguez says:

    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.

  4. Bill Pitre says:

    Shouldn’t this:

    echo “%home %(echo $HOME)” >> $HOME/.rpmmacros

    be changed to this?:

    echo “%home $(echo $HOME)” >> $HOME/.rpmmacros

  5. SGhosh says:

    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.

  6. jerry says:

    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

  7. Bill R. Williams says:

    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.

  8. John S. says:

    Ignore comment #4. It should be a % and not a $. That is, it is: echo “%home %(echo $HOME)” >> $HOME/.rpmmacros

Leave a reply