Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have read several places NEVER to build RPM's as the root user. As such, I defined a new user and have tried building out RPM structures there, however, using the

rpmbuild --rebuild

returns an error which states the topdir cannot be accessed:

Installing curl-7.20.1-1.src.rpm

error: cannot write to %sourcedir /usr/src/redhat/SOURCES

error: curl-7.20.1-1.src.rpm cannot be installed

does anybody know how to make this change? I have a correct /src/ directory set up under the new user.

share|improve this question
up vote 6 down vote accepted

from the Centos Wiki on how to setup a build enviroment (assuming you're enviroment is the same, change $HOME to a path or better variable as needed):

[userid@hostname ~]$ echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros

Beware: the second command will overwrite a previous .rpmmacros you might have, so you should check that you still do not have this file before running that command.

Basically what that is saying, is that you need to edit the users rpmmacros file to redirect the %_topdir macro to the new place on the file system that you want to be the topdir of your build environment.

share|improve this answer

You can also relocate topdir from the command line like this:

rpmbuild --define "_topdir $HOME/rpmbuild" --rebuild
share|improve this answer
Also short -D ... – 0xC0000022L Sep 4 '13 at 15:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.