How to Remove Orphaned Packages in Centos Linux

Keeping your Linux operating system organized and decluttered not only helps lower disk space but can speed up future updates or upgrades and provides less places for malware and viruses to hide.

In your favorite terminal, log on to your server and enter the following command.

dnf repoquery ------unneeded

This gives you a list of packages that DNF regards as no longer being needed by other installed packages. Of course, this may not mean it would be sensible to remove them, but it gives you a starting point for your investigations.


The following command will also show you a list of packages that are not dependencies and that DNF can remove using the autoremove command.

dnf list autoremove

DNF list autoremove

In the above example DNF says we can remove grub2-tools and libssh2 without breaking other packages.


Now enter the following command to automatically remove the packages that DNF thinks are orphaned.

dnf autoremove

DNF autoremove

It should be remembered that if you have installed packages independent of DNF then they may be dependent on the packages that autoremove claims it can safely remove. This command is powerful and has the potential to break your operating system if not used with care.