0

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
  • 2,643

1 Answers1

0

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'}}

sds
  • 2,643