How to remove all packages with DNF on which no other package depends on

7

1

My Problem

I wanted to build a piece of software by hand. So I installed all of its dependencies using dnf install <a> <b> <c>.

Then I didn't need that piece of software any more, and so I also wanted to uninstall all of its dependencies. But yum remove <a> <b> <c> would remove all packages, even if another installed package still depends on one of these packages (<b>, for example).

What I've Tried

  • I read the man dnf, but I couldn't find a suitable command.

My Question

What is the simplest way to:

  1. Find out which of the packages <a>, <b> and <c> are still needed by other packages.
  2. dnf remove all packages from my list of packages that I don't need anymore (<a>, <b> and <c>), but don't remove the packages from point (1.).

Any idea?

Thanks for your help. If anything's unclear, please comment and I'll add more details.

Franz-Josef Christbaumer

Posted 2015-07-20T20:08:45.127

Reputation: 73

Answers

1

For Fedora you can use package-cleanup, for example with the --leaves option.

--leaves List leaf nodes in the local RPM database. Leaf nodes are RPMs that are not relied upon by any other RPM.

bwt

Posted 2015-07-20T20:08:45.127

Reputation: 421

This does not work. I installed wine which has numerous dependencies totally over 800M of disk space, but if I do dnf remove wine and then package-cleanup --leaves --orphans, it doesn't detect any of those dependencies as being candidates for cleanup. – theferrit32 – 2020-02-11T16:56:46.413

13

With Yum, you would use the package-cleanup command from yum-utils. But, with DNF, it's built in as the dnf autoremove command. From the docs:

dnf [options] autoremove

Removes all “leaf” packages from the system that were originally installed as dependencies of user-installed packages but which are no longer required by any such package.

Note that you can also use the dnf list command to see which packages would be removed, before running the automremove itself, with

dnf list autoremove

Also note that DNF has another difference in behavior which should help you out in similar situations (but not your exact case). If your main piece of software were installed by DNF (rather than outside of DNF by hand), and you used dnf remove, the default (unlike yum) is to also remove any dependencies which were added just for that package and which aren't used for anything else.

mattdm

Posted 2015-07-20T20:08:45.127

Reputation: 2 324

Yum also had the autoremove option - also DNF i think now 'autoremoves' automatically anyway http://dnf.readthedocs.org/en/latest/cli_vs_yum.html#clean-requirements-on-remove-on-by-default

– Wilf – 2015-09-13T12:43:18.117

This does not work. I installed wine which has numerous dependencies totally over 800M of disk space, but if I do dnf remove wine and then dnf autoremove, it doesn't remove any of the dependencies. – theferrit32 – 2020-02-11T16:55:47.670

How did you install wine? It needs to be installed in a way that DNF knows to track the dependencies. Look at dnf repoquery --userinstalled – mattdm – 2020-02-11T17:03:02.673