8

On Gentoo, is there a way to find a list of installed packages which doesn't have other packages depended on them (so called leaf packages)? Or, is there analog of pkg-orphan FreeBSD utility?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
AlexD
  • 1,088
  • 1
  • 10
  • 14

2 Answers2

6

That's what emerge --pretend --depclean does. It looks for packages that are:

  • not depended upon by other ebuilds, and
  • neither in world nor system sets

It's a good idea to run emaint --check world to find (and later fix) potential problems with your world file before a depclean.

Other useful tools: Gentoo maintenance

Anthony Geoghegan
  • 12,605
  • 7
  • 59
  • 62
Mat
  • 51,578
  • 10
  • 158
  • 140
  • In my case, packages which I'm interested in (these perl modules from my other question) are all in world file. – AlexD Oct 02 '11 at 11:24
  • 2
    When you put stuff in world, it means "I depend on this". I.e. you are the dependency. Remove the packages that you don't explicitly need from your world file. When you emerge things you don't explicitly need, use the `--oneshot` option. – Mat Oct 02 '11 at 11:28
  • Adding to the previous comment by Mat: A proper command-line way to remove such packages from `world` is **`emerge --deselect package_atom`**, where `package_atom` can be simply the name of package (for more, see `man portage`). – rozcietrzewiacz Oct 02 '11 at 13:13
  • These packages are installed by puppet recipe so using `--oneshot` will require modifying puppet sources, and I need these packages included in world file in production anyway so they won't be removed by regular `depclean` (these packages are dependencies of large web application which is not properly packaged yet). But right now I need to clean these packages from test system and removing these packages by hand from world file (or from system) is exactly task which I'm trying to avoid. – AlexD Oct 07 '11 at 07:19
  • You can't have it both ways - tell the system they are required, then ask it for them to be cleaned up automatically. You need to track what you're doing. Sets will help a bit, but as you said in another comment it's not bullet-proof. You could also simply record all your emerge actions (with a simple wrapper) and use that to backtrack your changes. – Mat Oct 07 '11 at 07:22
  • Actually I can get that list of leaf packages by simply cycling over list of all packages calling `equery depends` for each, but this is very slow because there is seems to be no information on dependencies stored in `/var/db/pkg` (for example FreeBSD has +REQUIRED_BY for each package and it refuses to remove packages which have something depended on them) – AlexD Oct 07 '11 at 08:48
2

If you want to see what packages in the @world set are not also dependencies of other installed packages, you can run emerge --pretend --depclean @world (or emerge -pc @world). Also note that if you try to remove a package using emerge --depclean atom (instead of emerge --unmerge atom), portage will only remove the package if nothing else depends on it.

Jonathan Callen
  • 420
  • 2
  • 9
  • 3
    This does not work (anymore?) `emerge --pretend --depclean @world` returns `emerge: the given set 'world' does not support unmerge operations` – Jonas Stein Jan 02 '19 at 16:10