How to find installed deb packages needlessly marked as manually installed

Ondřej Grover

Problem statement

apt and aptitude both remember which packages were installed automatically as dependencies of some other package or manually for some reason. For various reasons the list of manually packages may become needlessly large and can start to accumulate over time. These packages will be uninstalled only when specifically requested.

One common example are library packages which may be installed as hotfix for some reason, but later they could be marked as automatically installed once some software depending on them is installed. However, if that doesn't happen, they will remain installed even once the packages depending on them are uninstalled. Tools like deborphan may find these left-over packages in some cases, but they have to guess a lot and it's not a systemic solution.

Description of a possible solution

That's why I'm looking for a way to find such packages that can be marked as automatically installed without them resulting to be uninstalled. This would mean finding packages that are currently marked as manually installed, but are dependencies (or recommended dependencies) of some other installed package. These packages could then be marked as automatically installed and will be removed once they are not needed anymore by other software.

I think I might be able to make a tool like that with the Python bindings for libapt, but I would hate to reinvent the wheel if something like that already exists.

Gilles 'SO- stop being evil'

Search for packages that are manually installed, and that are a mandatory or recommended dependency of an installed package. Aptitude can do that.

aptitude search -q -F %p '?installed !?automatic (?reverse-depends(?installed .*) | ?reverse-recommends(?installed .*))'

I don't think there's a way to indicate what dependency was found for each package. If you want that information, Python would be the way to go. This very quick-and-dirty script seems to do it (mostly, I think it may be incorrect in some non-straightforward cases involving disjunctions, version dependencies, pre-depends, …).

#!/usr/bin/env python2
import apt
packages = apt.Cache()
covered = {}
# Inverse dependency computation: for each installed package, record which
# packages require it (as Depends: or Recommends:).
for p in packages:
    if p.installed:
        for l in p.installed.dependencies + p.installed.recommends:
            for d in l:
                if packages.has_key(d.name) and packages[d.name].installed:
                    if not covered.has_key(d.name):
                        covered[d.name] = []
                    covered[d.name] += [p.name]
# Print out the manually installed packages that are required by another
# installed package, as well as the requiring package(s).
for p in sorted(covered.keys()):
    if not packages[p].is_auto_installed:
        print(' '.join([p] + covered[p]))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to find manually installed packages?

From Dev

Why are almost all packages marked as manually installed?

From Dev

Accidentally run "apt install *" now all packages are marked as "manually installed"

From Dev

How to list installed packages manually from backports?

From Dev

Meteorite change "manually" installed packages to automatically installed

From Dev

How to find docs for apt installed packages

From Dev

How to find docs for apt installed packages

From Dev

How to make cmake find installed packages

From Dev

how to find information about not installed packages

From Dev

How to find out where different packages are installed?

From Dev

How to view a list of packages that were manually installed without their dependancies

From Dev

How do I find a command associated with an installed .deb file?

From Dev

How can I determine which packages I have installed via homebrew and which were installed manually?

From Dev

How to uninstall a .deb installed with dpkg?

From Dev

How to remove installed packages

From Dev

How to remove installed packages

From Dev

How to make the unity app search find a manually installed app

From Dev

How to get installed/not installed state of **all** packages?

From Dev

How to uninstall MongoDB that was manually installed

From Dev

How are some deb packages found by dpkg-query while they have never been installed?

From Dev

How can I find executables installed by NuGet packages?

From Dev

How to find all the driver packages installed in my pc?

From Dev

how to find which packages are installed system-wide in NixOS?

From Dev

How do I find installed packages that have no install candidate?

From Dev

How to find specific package name from list of installed packages

From Dev

How to Find All Defaultly Installed Packages on Ubuntu 16.04.3

From Dev

How to find out what all standalone packages are installed?

From Dev

Generating list of manually installed packages and querying individual packages

From Dev

Is there a way to differentiate between System packages and Manually installed packages in Linux?

Related Related

  1. 1

    How to find manually installed packages?

  2. 2

    Why are almost all packages marked as manually installed?

  3. 3

    Accidentally run "apt install *" now all packages are marked as "manually installed"

  4. 4

    How to list installed packages manually from backports?

  5. 5

    Meteorite change "manually" installed packages to automatically installed

  6. 6

    How to find docs for apt installed packages

  7. 7

    How to find docs for apt installed packages

  8. 8

    How to make cmake find installed packages

  9. 9

    how to find information about not installed packages

  10. 10

    How to find out where different packages are installed?

  11. 11

    How to view a list of packages that were manually installed without their dependancies

  12. 12

    How do I find a command associated with an installed .deb file?

  13. 13

    How can I determine which packages I have installed via homebrew and which were installed manually?

  14. 14

    How to uninstall a .deb installed with dpkg?

  15. 15

    How to remove installed packages

  16. 16

    How to remove installed packages

  17. 17

    How to make the unity app search find a manually installed app

  18. 18

    How to get installed/not installed state of **all** packages?

  19. 19

    How to uninstall MongoDB that was manually installed

  20. 20

    How are some deb packages found by dpkg-query while they have never been installed?

  21. 21

    How can I find executables installed by NuGet packages?

  22. 22

    How to find all the driver packages installed in my pc?

  23. 23

    how to find which packages are installed system-wide in NixOS?

  24. 24

    How do I find installed packages that have no install candidate?

  25. 25

    How to find specific package name from list of installed packages

  26. 26

    How to Find All Defaultly Installed Packages on Ubuntu 16.04.3

  27. 27

    How to find out what all standalone packages are installed?

  28. 28

    Generating list of manually installed packages and querying individual packages

  29. 29

    Is there a way to differentiate between System packages and Manually installed packages in Linux?

HotTag

Archive