Monday, October 13, 2008

apt-get problem: The package index files are corrupted

My computer crashed today, due to the fact that I was testing my media server and foolishly tried to play a video through VNC. Silly me. Nothing worked short of a hard reboot.

When I started up my system again, the box popped up saying that there were updates ready to install. Since I like doing things via the command line, I did an apt-get upgrade and it didn't find any updates. The box down in the corner clearly stated that there were 4 updates to install, but they didn't show up anywhere. Later I tried to install easytag (a fantastic GTK+ based audio file renamer/tagger) and got an error:
...The package index files are corrupted...
What that meant I wasn't sure, and a lot of google searching yielded a lot of people with the problem with very few results. Certain things would install fine but others would give the same, scary sounding error. I found one source that even attempted to provide a solution other than "try 'apt-get clean'!" on the Ubuntu forums.

The solution provided sounded a little drastic, but they worked:
sudo rm /var/lib/apt/lists/*
sudo aptitude update
Rather than actually delete anything I opted to move all of the files in /var/lib/apt/lists/ to a temporary folder. This only caused the problem that there is a folder in there called "partial" that will be moved with the mv command that you have to move back to the original directory, or else you will get an error saying that the folder doesn't exist. After that, apt-get update rebuilds the previously corrupted index and installing programs works again. After doing this, my four previously invisible updates showed up and were upgraded no problem.


Anonymous said...

Easier to have just deleted them like you were told, since rm lists/* won't delete the directory.

Everything inside lists, other than the folder structure, is recreated by apt-get update or aptitude update. Deleting lists/* is to your apt-get index what apt-get clean is to your package cache.

Anonymous said...

thanks, nice work