Score:0

How do find multiply installed packages?

cn flag
sds

I just discovered that I have both gcc-10and gcc-11 installed (and did apt purge gcc-10 && apt autoremove).

I wonder what other packages I might have that are installed in multiple versions?

PS. It appears that gcc-12 exists too, but apt install gcc-12 && apt purge gcc-11 fails because of unmet dependencies)

sds avatar
cn flag
sds
@Nmath: the package system is supposed to take care of dependencies, so there should never be any breakage from `apt purge ...`. OTOH, the more unused packages you have, the more possibilities for damage/conflicts. I want to keep only what I use.
Nmath avatar
ng flag
See: [How to list all installed packages](https://askubuntu.com/q/17823). By the same logic that apt is supposed to take care of dependencies, then that package must exist on your system for some reason. My suggestion is to make backups and proceed with caution.
sds avatar
cn flag
sds
@Nmath: yes, there are many ways to list _all_ packages. This is _not_ the question. I am asking how to detect the same piece of software installed multiple times with different versions. E.g., both `gcc-10` & `gcc-11` or `emacs-22` & `emacs-23`.
Score:0
cn flag
sds

Here is what I ended up using:

import subprocess as sp

versioned = {}
with sp.Popen(["apt","list","--installed"], encoding="ascii",
              stdout=sp.PIPE, stderr=sp.STDOUT) as pipe:
    for pack in pipe.stdout:
        if "/" not in pack:
            print(pack)
            continue
        name = pack.split("/",1)[0]
        name_ver = name.rsplit("-",1)
        if len(name_ver) == 2 and name_ver[1].isdigit():
            versioned.setdefault(name_ver[0],set()).add(name_ver[1])

print(f"found {len(versioned):,d} versioned packages")
versioned = {n:v for n,v in versioned.items() if len(v) > 1}
print(f"found {len(versioned):,d} packages with multiple versions:\n{versioned}")

which prints

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.



Listing...

found 240 versioned packages
found 3 packages with multiple versions:
{'cpp': {'12', '11'}, 'g++': {'12', '11'}, 'gcc': {'12', '11'}}
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.