Ubuntu Error: Opening the Cache: Fix

So there I was. I had gained a strange icon on the task bar on my desktop on Ubuntu 20.04 LTS. It looked like a little red No Entry sign (sorry – I didn’t think to screenshot it). I had an error opening my cache apparently.

When I clicked the icon I got this.

Package manager error message about error on opening the cache on task bar
Package manager error message displayed when error icon clicked on taskbar

The package lists or status file could not be parsed or opened. So I thought I’d be a smart-arse and just do a manual package update, what more could be possibly wanted?

 

Doom!

Well no. Not Doom. Just irritating. I think the reason I had got into this state was that my machine had apparently locked up the day before. Like an impatient idiot I had forced it to turn off.

I now assume that this was probably while it was in mid flow doing an update. The result being that I managed to inadvertently wreck the status file or the package lists. So any new update failed before it had even started.

The actual error message from the package manager when I tried running it was this:

E: Read error - read (5: Input/output error)
E: The package lists or status file could not be parsed or opened.
E: _cache->open() failed, please report.

So how to fix this?

There’s lots of stuff all over Google about getting an error on opening the cache. Some of it going back ten years or more. Some is unclear and some contradictory. Other bits out-of-date or just plain wrong. I found a couple of answers that I amalgamated and succeeded in salvaging my machine. So this is what I did and it appears to have worked a treat for me. BUT… Caveat Emptor and all that. (I got the guts of this fix from Here)

First the scary bit. You have to delete all the files under directory /var/lib/apt/lists. But DO NOT delete the lists directory itself. (I didn’t back mine up my broken copy first (because at times I’m an idiot) but if you can maybe you should. After you have (or you decide not to) open a terminal and issue this:

sudo rm /var/lib/apt/lists/* -vf

Here’s what I got back.

chalkie@chalkie-TP550LA:/var/lib/apt/lists$ cd
chalkie@chalkie-TP550LA:~$ sudo rm /var/lib/apt/lists/* -vf
[sudo] password for chalkie: 
rm: cannot remove '/var/lib/apt/lists/auxfiles': Is a directory
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_InRelease'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_main_binary-amd64_Packages'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_main_binary-i386_Packages'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_main_cnf_Commands-amd64'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_main_dep11_Components-amd64.yml.gz'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_main_dep11_icons-48x48.tar.gz'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_main_dep11_icons-64x64%402.tar.gz'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_main_dep11_icons-64x64.tar.gz'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_main_i18n_Translation-en'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_multiverse_cnf_Commands-amd64'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_restricted_cnf_Commands-amd64'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_universe_binary-amd64_Packages'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_universe_binary-i386_Packages'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_universe_cnf_Commands-amd64'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_universe_dep11_Components-amd64.yml.gz'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_universe_dep11_icons-48x48.tar.gz'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_universe_dep11_icons-64x64%402.tar.gz'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_universe_dep11_icons-64x64.tar.gz'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal-backports_universe_i18n_Translation-en'
removed '/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_focal_InRelease'

Now you need to re-generate the files.

sudo apt clean
sudo apt update

Here’s what I got.

chalkie@chalkie-TP550LA:~$ sudo apt clean
chalkie@chalkie-TP550LA:~$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu focal InRelease [265 kB]       
Get:3 http://gb.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://gb.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages [515 kB]
Get:6 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease [3,065 B]
Get:7 http://gb.archive.ubuntu.com/ubuntu focal/main i386 Packages [718 kB]    
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1,822 kB]
Get:9 https://packages.microsoft.com/ubuntu/20.04/prod focal/main all Packages [2,176 B]
Get:10 http://gb.archive.ubuntu.com/ubuntu focal/main amd64 Packages [970 kB]  
Get:11 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 Packages [28.4 kB]
.
.
.
.
Get:112 http://gb.archive.ubuntu.com/ubuntu focal-backports/universe DEP-11 64x64 Icons [22.6 kB]
Get:113 http://gb.archive.ubuntu.com/ubuntu focal-backports/universe DEP-11 64x64@2 Icons [29 B]
Get:114 http://gb.archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [864 B]
Get:115 http://gb.archive.ubuntu.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]
Fetched 53.2 MB in 26s (2,032 kB/s)                                            
Reading package lists... Done
Building dependency tree       
Reading state information... Done
12 packages can be upgraded. Run 'apt list --upgradable' to see them.

Now finally you might as well do any upgrading to the file set (this does NOT upgrade you to a later version of Ubuntu – just to the latest version of the one your are on)

sudo apt dist-upgrade

Here’s what I got:

chalkie@chalkie-TP550LA:~$ sudo apt dist-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  libxmlb1
Use 'sudo apt autoremove' to remove it.
Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.
Learn more at https://ubuntu.com/pro
The following packages will be upgraded:
  aspnetcore-runtime-6.0 aspnetcore-targeting-pack-6.0 dotnet-apphost-pack-6.0
  dotnet-host dotnet-hostfxr-6.0 dotnet-runtime-6.0 dotnet-runtime-deps-6.0
  dotnet-sdk-6.0 dotnet-targeting-pack-6.0 libfprint-2-2 libfprint-2-tod1
  ubuntu-advantage-tools
12 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
Need to get 124 MB of archives.
After this operation, 2,048 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 ubuntu-advantage-tools amd64 27.11.3~20.04.1 [161 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 libfprint-2-2 amd64 1:1.90.2+tod1-0ubuntu1~20.04.9 [212 kB]
Get:3 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 libfprint-2-tod1 amd64 1:1.90.2+tod1-0ubuntu1~20.04.9 [44.6 kB]
.
.
.
Configuring...
--------------
A command is running to populate your local package cache to improve restore speed and enable offline access. This command takes up to one minute to complete and only runs once.
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
chalkie@chalkie-TP550LA:~$ 

Notice the end bit “Configuring…” Personally I took the one minute with a pinch of salt, left it for ten minutes and had a cup of coffee. I just let it run.

And that’s it! The little no-entry sign has vanished and I can now do updates/changes again!

Click here for the rest of my posts on Linux/Ubuntu issues.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>