Somehow, my apt
system got hosed on my Ubuntu 20.04.4 system, and now there are more than 1,800 packages that are marked as needing to be uninstalled.
This is from the Xubuntu
installation, which means I'm running the xfce
desktop.
I know that the recommended way to fix this kind of apt
problem is to do an apt autoremove
followed by reinstalls of the packages. However, if I do that, my system will then be totally unusable after the apt autoremove
, due to the fact that most of my system's packages will have been uninstalled.
I'm looking for an alternative way to fix my apt
database so that I don't have to destroy my system with the apt autoremove
command in order to correct apt
.
In order to illustrate the state of apt
on my system, here are some of the things I have run ...
% sudo apt-get install -f
[returns a list of the names of the 1,800 packages]
% sudo dpkg configure -a
[no output]
% sudo aptitude search ?broken
[no output]
% sudo cat /var/log/apt/history.log
Start-Date: 2022-05-04 18:01:54
Requested-By: [MYUSERID] (1000)
Upgrade: networkd-dispatcher:amd64 (2.1-2~ubuntu20.04.2, 2.1-2~ubuntu20.04.3), libvirt-daemon-system-systemd:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), openssl:amd64 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), librbd1:amd64 (15.2.14-0ubuntu0.20.04.2, 15.2.16-0ubuntu0.20.04.1), google-chrome-stable:amd64 (101.0.4951.41-1, 101.0.4951.54-1), libvirt-clients:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), iio-sensor-proxy:amd64 (2.8-1ubuntu1, 2.8-1ubuntu2), libvirt-daemon-driver-storage-rbd:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), libpq5:amd64 (12.9-0ubuntu0.20.04.1, 12.10-0ubuntu0.20.04.1), ubuntu-drivers-common:amd64 (1:0.9.0~0.20.04.6, 1:0.9.0~0.20.04.7), libvirt-daemon-driver-qemu:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), libvirt-daemon-system:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), libssl-dev:amd64 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), libssl-doc:amd64 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), libmysqlclient21:amd64 (8.0.28-0ubuntu0.20.04.3, 8.0.29-0ubuntu0.20.04.2), libmysqlclient21:i386 (8.0.28-0ubuntu0.20.04.3, 8.0.29-0ubuntu0.20.04.2), libvirt0:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16), lm-sensors:amd64 (1:3.6.0-2ubuntu1, 1:3.6.0-2ubuntu1.1), libsensors-config:amd64 (1:3.6.0-2ubuntu1, 1:3.6.0-2ubuntu1.1), libssl1.1:amd64 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), libssl1.1:i386 (1.1.1f-1ubuntu2.12, 1.1.1f-1ubuntu2.13), libsensors5:amd64 (1:3.6.0-2ubuntu1, 1:3.6.0-2ubuntu1.1), libsensors5:i386 (1:3.6.0-2ubuntu1, 1:3.6.0-2ubuntu1.1), librados2:amd64 (15.2.14-0ubuntu0.20.04.2, 15.2.16-0ubuntu0.20.04.1), libvirt-daemon:amd64 (6.0.0-0ubuntu8.15, 6.0.0-0ubuntu8.16)
End-Date: 2022-05-04 18:02:47
% sudo ls -l /etc/apt/sources.list
4 -rw-r--r-- 1 root root 3280 Jan 19 17:24 /etc/apt/sources.list
[note that the file hasn't changed in a few months]
% sudo ls -l /etc/apt/sources.list.d
total 16
4 -rw-r--r-- 1 root root 190 Jan 19 17:24 google-chrome.list
4 -rw-r--r-- 1 root root 190 Jan 19 17:24 google-chrome.list.save
4 -rw-r--r-- 1 root root 56 Apr 14 11:06 skype-stable.list
4 -rw-r--r-- 1 root root 56 Jan 19 17:24 skype-stable.list.save
[note that none of this has changed recently]
% sudo apt update
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:3 http://dl.winehq.org/wine-builds/ubuntu focal InRelease
Get:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:6 http://archive.canonical.com/ubuntu focal InRelease
Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease
Get:8 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [278 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [391 kB]
Get:10 http://us.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:11 http://us.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [9,568 B]
Get:12 http://us.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.8 kB]
Hit:13 https://repo.skype.com/deb stable InRelease
Get:14 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.6 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.3 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Fetched 1,155 kB in 2s (555 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
% sudo grep -r "^deb" /etc/apt/ --include=*.list
/etc/apt/sources.list.d/google-chrome.list:deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main
/etc/apt/sources.list.d/skype-stable.list:deb [arch=amd64] https://repo.skype.com/deb stable main
/etc/apt/sources.list.d.save/alex-p-ubuntu-aegisub-focal.list:deb http://ppa.launchpad.net/alex-p/aegisub/ubuntu focal main
/etc/apt/sources.list.d.save/teamviewer.list:deb https://linux.teamviewer.com/deb stable main
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal main restricted
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal main restricted
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal universe
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal-updates universe
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal-updates universe
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal multiverse
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal multiverse
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal-updates multiverse
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal-updates multiverse
/etc/apt/sources.list:deb http://us.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
/etc/apt/sources.list:deb-src http://us.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
/etc/apt/sources.list:deb http://archive.canonical.com/ubuntu focal partner
/etc/apt/sources.list:deb-src http://archive.canonical.com/ubuntu focal partner
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu focal-security main restricted
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu focal-security universe
/etc/apt/sources.list:deb-src http://security.ubuntu.com/ubuntu focal-security universe
/etc/apt/sources.list:deb http://security.ubuntu.com/ubuntu focal-security multiverse
/etc/apt/sources.list:deb-src http://security.ubuntu.com/ubuntu focal-security multiverse
/etc/apt/sources.list:deb http://dl.winehq.org/wine-builds/ubuntu/ focal main
I had a similar problem in the past which I fixed as described in the "Answers" section of the following post: apt forgot about more than 1,000 packages, and I'm unable to reinstall ... it's the Answer which begins with "I figured out how to fix this problem ..."
However, this seems like a hack-y way to fix this, and I'm not sure how reliable it will be if I run it now.
Can anyone suggest any other way to fix this problem without sudo apt autoremove
and without that hack-y method that I used in the past?
Thank you very much in advance.
PS: I take daily backups of my system. Are there perhaps any files or directories I can restore from my latest backup which would contain the non-broken versions of the apt
database?
PPS: I tried installing xubuntu-desktop
as discussed in the comments below. Sadly, it didn't help ...
% sudo apt install xubuntu-desktop
Reading package lists... Done
Building dependency tree
Reading state information... Done
xubuntu-desktop is already the newest version (2.233).
xubuntu-desktop set to manually installed.
The following packages were automatically installed and are no longer required:
[list of 1,800 package names, followed by ...]
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
And all those packages remain marked as requiring uninstallation.
I fixed the problem.
After reinstalling
xubuntu-desktop
andxubuntu-core
, my problem persisted. Therefore, I assume that the problem is not due to simply one missing installation at the top of the dependency tree, but rather, that the entireapt
database had probably somehow gotten corrupted.So, I gave up on shortcuts, I crossed my fingers, and I ended up biting the bullet and doing a slight variation of what I did in the past, as described in my Answer here: apt forgot about more than 1,000 packages, and I'm unable to reinstall
This time, I only did the install of each package, not the initial remove before each install, and it worked. Here are the steps I took ...
Step 1:
After running this, the
apt-installs
file contained this data ...Step 2:
I edited this
apt-installs
file to remove the top 4 lines and the bottom 2 lines, and I reformatted it so that there is one package name per line.Step 3:
I prepended the string
fixit
to the beginning of each line.Step 4:
I created a shell function called
fixit
to install the specified package, and I put that function at the top of theapt-installs
file. Now, here's what the first dozen or so lines ofapt-installs
look like ...Step 5:
I ran this:
This ran for around 30 minutes and reinstalled each of the packages. As can be seen in the
fixit
function, noremove
was done before eachinstall
.Step 6:
I then ran these two commands ...
This got
aptitude
back in sync with theapt
database.Everything seems back to normal now.
I'm guessing that if I knew what
apt
-related files/directories to reinstall from my recent backup, I could have fixed the problem that way, as well. However, I don't know enough about the lower-level internals ofapt
, and I couldn't quickly figure out what items would need to be restored.For future reference, I'd like to know this information about how to restore the
apt
database, because it will make it easier to fix this kind of problem if it occurs again.And many thanks to user535733!