How to: Fixing "Unable to parse package file /var/lib/apt/lists" Error in Raspberry Pi (SOLVED)

 Fixing "Unable to parse package file /var/lib/apt/lists" Error in Raspberry Pi


Reading package lists… Error!
E: Unable to parse package file /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_bionic_InRelease
E: The package lists or status file could not be parsed or opened.



A similar error can be encountered in Debian:

E: Unable to parse package file /var/lib/apt/extended_states (1)


The package cache file is corrupted‘. 

Handling “Unable to parse package file” error in Raspberry Pi and Debian-based Linux distributions

Here’s what you need to do. Take a closer look at the name and path of the file the Raspberry Pi is showing error on.

Reading package lists… Error!

E: Unable to parse package file /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_bionic_InRelease
E: The package lists or status file could not be parsed or opened.

For example, in the above error, it was pro about /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_bionic_InRelease

This gives you the idea that something is not right with this file. Now all you need to do is to remove this file and regenerate the cache.

sudo rm <file_that_is_not_parsed>

So in my case, I could use this command: 

sudo rm /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_bionic_InRelease 

and then rebuild the cache with 

sudo apt update command.

Step by step for beginners

If you are familiar with Linux commands, you may know how to delete the file with its absolute path. For novice users, let me guide you to delete the file safely.

First, you should go to the directory where the file is stored:

cd /var/lib/apt/lists/

Now delete the file which is not being parsed:

sudo rm archive.ubuntu.com_ubuntu_dists_bionic_InRelease

Now if you run the update again, the apt cache will be regenerated.

sudo apt update

Too many files cannot be parsed?

This is fine if you have one or two files that are not being parsed while updating the system. But if the system complains about ten or twenty such files, removing them one by one is too tiring.

What you can do in such a case to remove the entire cache and then generate it again:

sudo rm -r /var/lib/apt/lists/* sudo apt update

Explanation of how it fixed your problem

The /var/lib/apt is the directory where files and data related to the apt package manager are stored. The /var/lib/apt/lists is the directory that is used for storing information for each package resource specified in your system’s sources.list.

In slightly noncomplicated terms, this /var/lib/apt/lists stores the package information cache. When you want to install or update a program, your system checks in this directory for the information on the said package, if it finds the detail on the package, then it goes to the remote repository and actually downloads the program or its update.

When you run the sudo apt update it builds the cache. This is why even when you remove everything in the /var/lib/apt/lists directory, running the update will build a fresh cache.

This is how it handles the issue of files not being parsed. Your system complained about a particular package or repository information that somehow got corrupted (either a failed download or manual change to the sources.list). Removing that file (or everything) and rebuilding the cache solves the issue.

Still facing error?

This should fix the issue for you. But if the problem still persists or if you have some other related issue, let me know in the comment section and I’ll try to help you out.

Post a Comment

0 Comments