Setting up an RPM build environment

May 21, 2007 by · 10 Comments 

Back when I started this site I was recommending that users go through the process of chown-ing chmod-ing the /usr/src/redhat folder so that it was writable by a normal user account as opposed to only root. A few weeks back a user brought up the question of why I was doing this. Well, the answer is "it's just the way I've always done things"...

When I started using Linux a decade or so ago I was taught that this was where you built rpms. Later, when told that I shouldn't be compiling as root, I simply created a new user, changed the permissions on that folder tree, and went about my business. The truth is, there's absolutely nothing wrong with this process if you're the only user of the system. However, you can run into real permission problems and conflicts if there are multiple users on the box and more than one want to build an RPM...

As was mentioned earlier, about a month ago, a kind user, Colin Guthrie, questioned my process. Thankfully, in the spirit of sharing, he also posted an alternative method. While I think his process is a bit more time consuming to implement, it really does provide a safer environment, particularly if you have multiple users. As such, it has been detailed below (cleaned up slightly from his original post).

$ mkdir ~/rpms
$ cd ~/rpms
$ mkdir BUILD RPMS SOURCES SPECS SRPMS tmp
$ cat > ~/.rpmmacros
%_topdir /home/username/rpms
%_tmppath /home/username/rpms/tmp
Press [Ctrl]+[D]

Make sure that you modify lines 5 & 6 so that "/home/username" is replaced by the correct path for your user's home directory.

From that point you're ready to go. Simply install your src.rpm as normal and the files will be unpacked in your new build tree.

Comments

10 Responses to “Setting up an RPM build environment”
  1. Ayourk says:

    When I tried to use "~/", rpmbuild couldn't find my source files. I had to actually use the full path of my builduser's home directory (/home/builduser).

  2. Jason says:

    Interesting, the info I originally typed above only seems to work on one of my systems... I've updated the info for the .rpmmacros file. Thanks for the catch.

  3. Leif Gruenwoldt says:

    There's an even easier way to setup the rpm build tree.

    If you install the packaged "rpmdevtools" and then run "rpmdev-setuptree" it will make you a ~/rpmbuild directory with proper sub directories. It will even make you a ~/.rpmmacros file.

  4. Jason says:

    I don't believe that there is an 'rpmdevtools' package in RHEL or CentOS, at least not in the official repos.

  5. Remi says:

    rpmdevtools are available in EPEL (Fedora community repo for Enterprise Linux)

    http://download.fedora.redhat.com/pub/epel/4/

    Remi

  6. Philip Snyder says:

    Awesome. First time I've ever built an rpm and I was having a ton of trouble figuring it out. Once I setup this environment, everything was peachy! Thanks!

  7. William says:

    How do you include man pages in the build tree?

  8. ep says:

    You can also use:
    %_topdir %(echo $HOME)/rpmbuild
    %_tmppath %(echo $HOME)/rpmbuild/tmp

Trackbacks

Check out what others are saying about this post...
  1. My Hobby is Programming » Blog Archive » Setting up an RPM build environment says:

    [...] read more | digg story [...]

  2. Patch and Rebuild Redhat Kernel for atop enhanced statistics – VirtFoundry says:

    [...] I don’t care about building the kernel RPM as root. But a more appropriate method can be seen here if you [...]



Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.