April 17, 2025

Getting unstuck in apt when having a higher version of a package

I don't know why, but somehow, an incorrect version of a package got installed. Here's the story of how I fixed it using all the tricks in the book to get unstuck. Alternate title: "how messing up your system so many times over the years helps you fixing it... eventually".

The last time this happened to me must have been about two decades ago when I installed Debian for the first time, trying to see how "apt-get" fared against Mandrake's "urpmi" and eventually coming to the conclusion that Gentoo's "emerge" was better (ah, the naivety of youth).

So this time, I wanted to install that very innocuous "-dev" package and it threw an error like so. (I haven't bothered translating the messages. If you can't understand from the context, ask DeepL.)

# apt install somethingLes paquets suivants contiennent des dépendances non satisfaites : libx11-dev : Dépend: libx11-6 (= 2:1.8.4-2+deb12u2) mais 2:1.8.6-1 devra être installé libx11-xcb-dev : Dépend: libx11-xcb1 (= 2:1.8.4-2+deb12u2) mais 2:1.8.6-1 devra être installé

Ok, it happens. It's usually either because you're trying to install something that is truly not compatible with your system or you just have stale repositories indexes. Knowing that a "-dev" package is rarely a problem especially since I didn't even specify a version, I went ahead with the regular "apt update" and "apt upgrade" process.

No luck, same error. So I asked my trusty "apt-cache policy" what was the matter with "libx11-6":

# apt-cache policy libx11-6libx11-6:  Installé : 2:1.8.6-1  Candidat : 2:1.8.6-1 Table de version :     2:1.8.12-1 10         10 http://deb.debian.org/debian unstable/main amd64 Packages *** 2:1.8.6-1 100        100 /var/lib/dpkg/status     2:1.8.4-2+deb12u2 500        400 http://deb.debian.org/debian bookworm/main amd64 Packages        500 http://security.debian.org/debian-security bookworm-security/main amd64 Packages

First thing, I like to live dangerously and ignore Debian's warning regarding having an unstable source. Still, that couldn't be the source of the error because I had pinned it's priority to 10 (very much lower so only to be installed when requested explicitely). Second thing, where is that "1.8.6" version even coming from? Not sure, but to be safe, I cleaned my apt sources as much as I could and tried again the "update" then "upgrade" process. No luck: the version was indeed higher, so the usual priority stuff didn't work, that is to say 400 is higher than 100, but 1.8.6 is higher than 1.8.4.

So, I knew I needed to install the "1.8.4" version instead so I just tried requesting it explicitely:

# apt install 'libx11-6=2:1.8.4-2+deb12u2'

And the result would be to remove almost every graphical program installed... Figures: something called "libx11" is probably linked in some way to every GUI in the system. So I needed a smarter tool becase I wasn't actually removing the library, only replacing it. I first turned to my aptitude (not my technical ability, the program). It sometimes comes up with a plan to get unstuck. It's a lazy solution, but if it works, why not try? But it didn't. To be faire, I haven't heard about aptitude for a while. It is still a perfectly valid program, but "apt" has gotten good enough that "getting automatically unstuck" is not a feature in very high demand.

At that point, I had to resort to the tool of ultimate necessity, the quintessential footgun, the "with power comes great responsibilty... just kidding don't even try" solution: "dpkg". Ok, in most case, it would have been a bad idea to do this, but I knew I merely wanted to remove a library and replace it with the same one, tow minor versions down. So here goes:

# dpkg --force-depends -r libx11-6dpkg: libx11-6:amd64 : problèmes de dépendance, mais suppression comme demandé : zutty dépend de libx11-6. xsettingsd dépend de libx11-6.[...] a bunch of warnings# dpkg --force-depends -r libx11-xcb1[...] basically the sasme warnings# apt --fix-broken installLecture des listes de paquets... FaitConstruction de l'arbre des dépendances... FaitLecture des informations d'état... Fait      Correction des dépendances... FaitLes paquets supplémentaires suivants seront installés :  libx11-6 libx11-xcb1Les NOUVEAUX paquets suivants seront installés :  libx11-6 libx11-xcb10 mis à jour, 2 nouvellement installés, 0 à enlever et 0 non mis à jour.Il est nécessaire de prendre 952 ko dans les archives.Après cette opération, 1 858 ko d'espace disque supplémentaires seront utilisés.Souhaitez-vous continuer ? [O/n]Réception de :1 http://deb.debian.org/debian bookworm/main amd64 libx11-6 amd64 2:1.8.4-2+deb12u2 [760 kB]Réception de :2 http://deb.debian.org/debian bookworm/main amd64 libx11-xcb1 amd64 2:1.8.4-2+deb12u2 [192 kB]952 ko réceptionnés en 0s (5 476 ko/s)Sélection du paquet libx11-6:amd64 précédemment désélectionné.(Lecture de la base de données... 352874 fichiers et répertoires déjà installés.)Préparation du dépaquetage de .../libx11-6_2%3a1.8.4-2+deb12u2_amd64.deb ...Dépaquetage de libx11-6:amd64 (2:1.8.4-2+deb12u2) ...Sélection du paquet libx11-xcb1:amd64 précédemment désélectionné.Préparation du dépaquetage de .../libx11-xcb1_2%3a1.8.4-2+deb12u2_amd64.deb ...Dépaquetage de libx11-xcb1:amd64 (2:1.8.4-2+deb12u2) ...Paramétrage de libx11-6:amd64 (2:1.8.4-2+deb12u2) ...Paramétrage de libx11-xcb1:amd64 (2:1.8.4-2+deb12u2) ...Traitement des actions différées (« triggers ») pour libc-bin (2.36-9+deb12u7) ...

Exit code 0. Done.