Hard 'cannot divert directories' error - libc wrong version

I’ve tried lots of suggestions to fix this, but it is very persistent.

Ubuntu Version:
Ubuntu 22.04 LTS

Desktop Environment (if applicable):

using bash

Problem Description:

When I try to update or upgrade my system, I get:

"
dpkg-divert: error: cannot divert directories

Use --help for help about diverting files.
dpkg: error processing archive /var/cache/apt/archives/libc6_2.39-0ubuntu8_amd64.deb (–unpack):
new libc6:amd64 package pre-installation script subprocess returned error exit status 2
"

Relevant System Information:

Distributor ID: Ubuntu
Description: Ubuntu 22.04 LTS
Release: 22.04
Codename: jammy

Screenshots or Error Messages:

Preparing to unpack .../libc6_2.39-0ubuntu8_amd64.deb ...
Checking for services that may need to be restarted...
Checking init scripts...
Checking for services that may need to be restarted...
Checking init scripts...
Stopping some services possibly affected by the upgrade (will be restarted later):

dpkg-divert: error: cannot divert directories

Use --help for help about diverting files.
dpkg: error processing archive /var/cache/apt/archives/libc6_2.39-0ubuntu8_amd64.deb (--unpack):
 new libc6:amd64 package pre-installation script subprocess returned error exit status 2
Errors were encountered while processing:
 /var/cache/apt/archives/libc6_2.39-0ubuntu8_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

What I’ve Tried:
‘’’
sudo apt --fix-broken install
sudo apt --fix-broken install
sudo apt-get update && sudo apt-get upgrade
sudo dpkg --configure -a
sudo apt install --reinstall libtirpc3 libc-bin libc6 libtirpc3t6
sudo apt-get dist-upgrade
sudo for file in $(LANG=C dpkg-divert --list | grep -oP ‘(?<=local diversion of )[^\s]+’); do dpkg-divert --local --no-rename --remove “${file}” || : ; divert_to="/tmp/$(echo “${file}” | sed 's|/||g’)" ; dpkg-divert --add --local --no-rename --divert “${_divert_to}” “${file}” || : ; done
sudo apt-get autoclean
sudo apt-get clean
sudo dpkg-divert --rename /usr/include/linux
sudo apt install build-essential
sudo apt install libc6_2.39-0ubuntu8_amd64.deb
‘’’


This is not the 22.04 version of libc but the 24.04 one, how did you get into that situation, did you mess up your sources.list files by adding noble anywhere ?

https://launchpad.net/ubuntu/+source/glibc

2 Likes

Post the output of inxi -r please and wrap with code tags.

If not installed, then sudo apt install inxi

1 Like
Repos:
  Active apt repos in: /etc/apt/sources.list
    1: deb http://cz.archive.ubuntu.com/ubuntu/ noble main universe
  No active apt repos in: /etc/apt/sources.list.d/alessandro-strada-ubuntu-ppa-yakkety.list
  No active apt repos in: /etc/apt/sources.list.d/digitalocean-agent.list
  Active apt repos in: /etc/apt/sources.list.d/droplet-agent.list
    1: deb [signed-by=/usr/share/keyrings/droplet-agent-keyring.gpg] https://repos-droplet.digitalocean.com/apt/droplet-agent main main
  No active apt repos in: /etc/apt/sources.list.d/megasync.list
  No active apt repos in: /etc/apt/sources.list.d/ondrej-ubuntu-php-artful.list
  No active apt repos in: /etc/apt/sources.list.d/ondrej-ubuntu-php-disco.list
  No active apt repos in: /etc/apt/sources.list.d/ondrej-ubuntu-php-eoan.list
  Active apt repos in: /etc/apt/sources.list.d/ookla_speedtest-cli.list
    1: deb [signed-by=/etc/apt/keyrings/ookla_speedtest-cli-archive-keyring.gpg] https://packagecloud.io/ookla/speedtest-cli/ubuntu/ jammy main
    2: deb-src [signed-by=/etc/apt/keyrings/ookla_speedtest-cli-archive-keyring.gpg] https://packagecloud.io/ookla/speedtest-cli/ubuntu/ jammy main
  No active apt repos in: /etc/apt/sources.list.d/ubuntustudio-ppa-ubuntu-backports-eoan.list

I got into this mess, some months ago, when I tried to update my system to noble, but it failed somehow. I was trying to upgrade to 24.04, and I’d still like to do that, but I end up with this error when I do.

For me the issue was that libc preinst script assumes usrmerge being completed on the system, but that wasn’t the case.

Fix was to install usrmerge package from jammy, eg.

apt-get install usrmerge/jammy

and then attempt the upgrade.