Keeping apt archives empty…or not.
In this post, Steven Hanley wonders how to keep /var/cache/apt/archives empty on a machine that has a full mirror of debian on it.
That’s actually the wrong question.
The right question is ‘Why is /var/cache/apt/archives even relevant on a machine with a full mirror of debian?’
/etc/apt/sources.list has always supported file:/ URLs. for example, sources.list on my local debian mirror looks like this:
deb file:/home/ftp/debian unstable main contrib non-free deb file:/home/ftp/debian-multimedia/ unstable main
With a file URL, apt-get doesn’t need to download any packages, and thus doesn’t need to cache anything in /var/cache/apt/archives. No need to keep it empty, it just is empty.
In a related post, Andrew Pollock suggests adding DPkg::Post-Invoke { “apt-get clean”; }; to /etc/apt/apt.conf.
That would be fine if you ONLY ever ran “apt-get update ; apt-get dist-upgrade”.
It’s not fine if you run “apt-get -d” to download packages first, then install a few packages with “apt-get install package”, and then run “apt-get dist-upgrade”.
If you try that, then the DPKG::Post-Invoke rule will clean out /var/cache/apt/archives when you install the individual package(s). When you then run the dist-upgrade, apt-get will have to download all the packages again.
Better just to get into the habit of running apt-get clean or autoclean occasionally when you want to reclaim some disk space.
April 29th, 2008 at 3:05 am
I’m wondering same thing. But my problem is slightly different. I use apt-cacher for my local machine and my chroots, and I want to keep those /var/cache/apt/archives clean. But since there is no apt mirror, I can’t use file:// adresses in sources.list.
Thanks
April 29th, 2008 at 7:11 am
just run “apt-get clean” after running “apt-get upgrade”
April 29th, 2008 at 3:08 pm
Unfortunately this is manual way. I want to clean archive after installation is done, automatically. Because sometimes builds in chroots fail because of lack of space, and apt archive contains hundreds of megabytes packages
April 29th, 2008 at 10:50 pm
So use the DPkg::Post-Invoke method that Andrew P blogged about. It’s a good solution for some circumstances, including yours.
The price is that because it always cleans the /v/c/a/archives, it will occasionally delete something before you want it deleted so you’ll have to download it again. no big deal if it’s cached in a local apt-cacher proxy.
April 30th, 2008 at 8:21 pm
Unfortunately DPkg::Post-Invoke { “apt-get clean”; }; gives this error:
E: Could not get lock /var/cache/apt/archives/lock - open (11 Resource temporari ly unavailable)
E: Unable to lock the download directory
E: Problem executing scripts DPkg::Post-Invoke ‘apt-get clean’
E: Sub-process returned an error code
But DPkg::Post-Invoke { “/bin/rm var/cache/apt/archives/*.deb”; };
does the job well.
Thanks
April 30th, 2008 at 9:38 pm
yeah, of course. it can’t run ‘apt-get clean’ because apt is still running and has a lock on the archives.
you could also try something like:
DPkg::Post-Invoke { “echo apt-get clean | at now + 5 minutes”; };
no idea if it works. just the first thing that came into my head.
April 30th, 2008 at 9:55 pm
It may not be guaranteed to run. We can’t know if installation is done n minutes after the first package installed