Saturday, June 2, 2018

Remove package on CentOs

If you have made some mistake and want to uninstall some package, you need an exact name of the package.

Find the exact name of the package this way:
$ sudo rpm -qa | grep -i <expected part of the package name like "mysql">

Uninstall the packages via yum:
$ sudo yum remove <the exact package name like "mysql-community-server-8.0.11-1.el7.x86_64">

Check the package name again:
$ sudo rpm -qa | grep -i <expected part of the package name>

Then run:
$ sudo rpm -e <the exact package name>
to remove it.


Detail


According to http://rikers.org/rpmbook/node19.html, the rpm -e command does the following:
The rpm -e command (--erase is equivalent) removes, or erases, one or more packages from the system. RPM performs a series of steps whenever it erases a package:
It checks the RPM database to make sure that no other packages depend on the package being erased.
It executes a pre-uninstall script (if one exists).
It checks to see if any of the package's config files have been modified. If so, it saves copies of them.
It reviews the RPM database to find every file listed as being part of the package, and if they do not belong to another package, deletes them.
It executes a post-uninstall script (if one exists).
It removes all traces of the package (and the files belonging to it) from the RPM database.