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!
$HOME?sudo rpm -e package-version.platform.rpminstead ofsudo 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...