Setting up an RPM build environment
May 21, 2007 by Jason · 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.
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).
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.
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.
I don't believe that there is an 'rpmdevtools' package in RHEL or CentOS, at least not in the official repos.
rpmdevtools are available in EPEL (Fedora community repo for Enterprise Linux)
http://download.fedora.redhat.com/pub/epel/4/
Remi
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!
How do you include man pages in the build tree?
You can also use:
%_topdir %(echo $HOME)/rpmbuild
%_tmppath %(echo $HOME)/rpmbuild/tmp