I have encountered a strange and annoying problem when trying to uninstall certain in-house generated rpm packages using sudo. When I do the following:

sudo rpm -e mypackage  
rpm -qa | grep mypackage

I find that the package is still listed! This is despite rpm -e running without any obvious errors. This then prevents me from removing other packages which this package depends on.

After some investigation I've discovered that the package includes a post uninstall script-let which seems to fail. The script-let simply tries to remove a directory, e.g.

rm -rf /some_directory

I then discovered that by bypassing this script the package will uninstall. So if I do:

sudo rpm -e --noscripts mypackage  
rpm -qa | grep mypackage

then the package is no longer listed. Now my question is why should using sudo prevent such a simple script from running, and secondly why does the rpm command not report a problem?

BTW, the following command sequence also works, so removing the directory is surely possible:

sudo rm -rf /some_directory  
sudo rpm -e mypackage  
rpm -qa | grep mypackage

Neither of these is really an acceptable solution as I need a reliable generic way of properly uninstalling rpm packages that are not under my control. It's also not possible for me to do this as root because I'm writing a script that other users must be able to run.

Finally in desperation I tried the -H option of sudo, i.e.

sudo -H rpm -e mypackage

Now this also seems to work, but can anybody explain why setting $HOME to /root could make any difference? Due to strict processes in my work environment I cannot really submit this as a solution without a convincing argument, i.e. I must be able to explain why -H is needed and prove that my script is robust. Just saying sudo -H seems to work on my machine is not going to cut it with my boss unfortunately!

I'm hoping that some expert on here can explain what is going on, and any help would be much appreciated!

  • Can we have a look at the script? Could it perhaps be removing files from $HOME?
    – terdon
    Aug 2, 2013 at 18:35
  • Thanks. I don't have access to it now, but really it was just a one line script removing a directory with a fixed path like "rm -rf /a/b/". So no obvious connection with $HOME. Also manually running that command with sudo also works fine and the directory is removed (without needing to use -H)!
    – user556144
    Aug 2, 2013 at 18:58
  • I had the same error message when I tried to invoke sudo rpm -e package-version.platform.rpm instead of sudo rpm -e package-version. Just wanted to share, since I landed on your question searching for why I couldn't uninstall a package that I knew I had installed... Feb 10, 2016 at 15:20

1 Answer 1


I've now discovered the explanation myself, but it might be helpful to others in the future. I found a file called .rpmmacros in my home area which was not present in the home area of root. Hence the impact of setting -H when calling sudo.

This .rpmmacros file set %_topdir to a directory that was not mounted (actually a clearcase vob). Mounting the directory or deleting the file then solved my problem, i.e. I was then able to uninstall the RPM without the -H option.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .