We often told that building an RPM as root is a bad thing. While this is very true, how do you build it as a normal user?

The trick is to use rpmdev-setuptree. This will create a empty build tree in ~/rpmbuild as well as sort out you .rpmmacro file so rpmbuild knows to use it.

It’s really simple actually, so here goes.

  1. As root, install rpm-build, rpmdevtools and yum-utils.
    yum -y install rpm-build rpmdevtools yum-utils
  2. Now as a user, create a rpmbuild tree:
    rpmdev-setuptree
  3. Now as a user, download your RPM source:
    yumdownloader -source sox
  4. Again as a normal user, install the source rpm
    rpm -ivh <rpm>.src.rpm
  5. Go in to ~/rpmbuild and make whatever changes you need to. The Spec file will be in ~/rpmbuild/SPECS and the source will be gzipped in ~/rpmbuild/SOURCES
  6. Now build it!
    rpmbuild -ba ~/rpmbuild/SPECS/<spec file>
  7. Assuming everything went OK, the RPMs will be in ~/rpmbuild/RPMS/, but you’ll need to install them as root.
  8. If you find your rpmbuild is getting full of crap, you can either delete it and rebuild it, or a slightly more elegant way would be to use
    rpmdev-wipetree