Linux: Uninstalling Packages with RPM
scottalanmiller last edited by scottalanmiller
After installing packages, uninstalling them is the next most important task that we will do with the rpm command.
To remove a package, we simply need to use the erase or "-e" flag. Here is an example:
# rpm -e yum
This will uninstall the first occurance of the yum package found in the database. Sometimes that is fine. Sometimes we might have different versions installed and need additional control. If you use rpm to query the system with
rpm -q yumfor example, we will know exactly what to put into the command:
# rpm -e yum-3.2.29-69.el6.centos.noarch
This is a bit more precise. Now considering that there might be multiple versions and perhaps we don't want to be precise and just want them all gone, we can address that, too. For this we will use the "--allmatches" flag like so:
# rpm -e --allmatches yum
All versions and architectures of yum will be removed.
Now, of course, just like when we are installing there is the possibility that there will be packages that depend on the one that we are removing. Be default rpm will protect us from removing something that is needed by something else in the system. We can, as always, override this if we really, truly know what we are doing!
# rpm -e --nodeps yum
Now when would we want to do this? A good example is when we need to remove one package now on which things depend and replace it with a different package that does something similar and those packages will happily use that as well. Examples of this are moving from MySQL to MariaDB or from Sendmail to Postfix.
As always, these are the common flags that Linux admins should know. The documentation has many more for special cases.