How to Remove Packages with Dependencies Using Yum

Normally, removing a package using YUM package management system will remove that package together with its dependencies. However, certain dependencies will not be removed on the system, these are what we can term as “unused dependencies” or (so-called “leaf packages” according to YUM man page).

Read Also: 4 Ways to Lock Package Install or Updates Using Yum

In this article, we will explain two ways to remove or uninstall a package along with their dependencies using YUM package manager in CentOS and RHEL distributions.

1. Using YUM’s Autoremove Option

This method requires you to add the directive clean_requirements_on_remove in YUM’s main configuration file /etc/yum.conf. You can use your favorite command line editor to open it for editing as shown.

# vim /etc/yum.conf

Then add the following line to the /etc/yum.conf file as shown in the output below. A value of one indicates that the directive is enabled (or turned on), a zero means otherwise.

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=19&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

clean_requirements_on_remove=1

Save the changes and exit the file.

From now, every time you remove a packages, YUM goes through each package’s dependencies and remove them if they are no longer needed by any other package.

# yum autoremove

2: Using yum-plugin-remove-with-leaves Plugin

This extension removes any unused dependencies that were added in by an installation package, but would not be removed automatically. It also helps you to keep a system clean of unused libraries and packages.

First install this extension on your system using following yum command.

# yum install yum-plugin-remove-with-leaves

Once you have installed the extension, each time you want to remove a package, add the --remove-leaves flag, for example.

# yum remove policycoreutils-gui --remove-leaves

For more information, check out YUM’s man page:

# man yum

That’s all! In this short article, we’ve shown two useful ways to remove a package along with unused dependencies using YUM. If you have any queries, use the comment form below to reach us.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.