Linux RedHat / CentOS / Fedora : Uninstall a package along with dependencies

If you’ve been wondering how to delete a package you mistakenly installed (or which is no longer needed) along with all its dependencies, here’s a neat way to achieve just that.

The idea is that whenever you use yum to perform some operation on packages, a transaction is created. If you installed a package along with its dependencies, then you can undo just that by undoing that transaction.

Recover the transaction ID you want to undo

Let’s say I want to uninstall owncloud :

[root@sakana html]# yum history list owncloud
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     6 | install owncloud         | 2015-03-31 20:46 | Install        |   99 EE
history list
[root@sakana html]# 

Here, the transaction we are interested in has ID = 6.

Undo the transaction

Once we have that ID, we can just undo the transaction as follows :

[root@sakana html]# sudo yum history undo 6
Undoing transaction 6, from Tue Mar 31 20:46:01 2015
    Dep-Install apr-1.5.1-1.fc20.x86_64                              @updates
    Dep-Install apr-util-1.5.3-1.fc20.x86_64                         @updates
    Dep-Install audit-libs-python-2.4.1-1.fc20.x86_64                @updates
    Dep-Install checkpolicy-2.1.12-5.fc20.x86_64                     @fedora
[Long list of packages and stuff...]
 perl-libs               x86_64 4:5.18.4-292.fc20 -                       0.0  
 libzip                  x86_64 0.11.2-1.fc20     -                       0.0  
 php-pdo                 x86_64 5.5.22-1.fc20     -                       0.0  
 perl-Pod-Escapes        noarch 1:1.04-292.fc20   -                       0.0  

Transaction Summary
================================================================================
Remove         82 Packages (+49 Dependent packages)
Not installed  17 Packages

Installed size: 311 M
Is this ok [y/N]: 

If you’re happy with the output, you can just proceed by typing Y and enter to validate.

Yum will then remove the listed packages, and you’re done.

(Credit : StackExchange)