Objective

The objective is to remove all orphaned packages from CentOS Linux. By orphaned packages we mean all packages which no longer serve a purpose of package dependencies.

For example, package A is depended on package B, thus, in order to install package A the package B must also be installed. Once the package A is removed the package B might still be installed, hence the package B is now orphaned package.

Operating System and Software Versions

  • Operating System: - CentOS 7

Requirements

Privileged access to you CentOS Linux system will be required.

Difficulty

EASY

Conventions

  • # - requires given command to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - given command to be executed as a regular non-privileged user

Instructions

STEP 1

First check whether a package-cleanup is available. If not, use the below command to install it:
# yum install yum-utils

Obtain List of Orphaned Packages

Next, use package-cleanup to obtain list of orphaned packages currently residing in the system:
$ package-cleanup --leaves
The above command will create a list of all orphaned packages, for review, one package per line.

Remove Orphaned Packages

Lastly, use yum remove to remove the entire list:
# yum remove `package-cleanup --leaves`
Note, you might need to run the above commands few times to uninstall all orphaned packages. Make sure to generate a preview of all packages to be removed and review them after each iteration.