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,543
  • @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. – sds Oct 24 '22 at 23:13
  • 1
    See: How to list all installed packages. 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. – Nmath Oct 24 '22 at 23:16
  • @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. – sds Oct 25 '22 at 14:29

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,543