clear apt-get list

I am building an image for an embedded Linux based on Debian. I did use apt-get update before on the device that I want to use as a base for that image, so the lists under /var/lib/apt/lists are quite large (almost 100 MB in size).

I want to keep apt-get functionality (so I don’t want to remove apt repositories) but I want to free the space used up in these lists (the lists almost double the size of the image).

Does anyone know how to do that? Can I just delete the files under /var/lib/apt/lists?

Asked By: Dakkaron


You can just use:

rm -rf /var/lib/apt/lists/*

This will remove the package lists. No repositories will be deleted, they are configured in the config file in /etc/apt/sources.list. All that can happen is that tools like apt-cache cannot get package information unless you updated the package lists. Also apt-get install will fail with E: Unable to locate package <package>, because no information is available about the package.

Then just run:

apt-get update

to rewrite those lists and the command will work again.

Anyway, it’s recommended to run apt-get update before installing anything.

Answered By: chaos

The lists are the knowledge of what’s available, so if you delete them, you won’t be able to install anything – that’s exactly equivalent to removing the repositories from your sources list (which you say you don’t want to do).

One option is that you could compress the lists, and remember to uncompress them before you next update.

What I often do (particularly when I want to experiment with extra sources) is to create a directory /etc/apt/sources.available and add entries for distributions. I can then easily enable any subset by creating symlinks from /etc/apt/sources.list.d and disable by removing those symlinks.

With empty sources list, you could apt-get update – that should clear your /var/lib/apt/lists. Then link appropriate sources back into /etc/apt/sources.list.d, but don’t update until such time as you actually intend to use them.

Answered By: Toby Speight
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.