I have installed Apt-Cacher NG to provide a cache of packages for several machines. I therefore see no point in having aptitude/apt-get keeping their own (second) cache in /var/cache/apt/archives. I realise I can empty this cache with sudo apt-get clean, but is there some way of configuring apt-get to automatically clean the cache when an install has completed?

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

I think what you can do is add a config file to /etc/apt/apt.conf.d/ named like no-cache containting Dir::Cache ""; and Dir::Cache::archives ""; according to manual of apt.conf. However, there is a bug that prevents this method from working.

So there is one remaining method according to this tutorial:

echo 'DPkg::Post-Invoke {"/bin/rm -f /var/cache/apt/archives/*.deb || true";};' | sudo tee /etc/apt/apt.conf.d/clean

This will carry out rm command just before apt quits.

link|improve this answer
I found just setting the cache path to an empty path gave an error when running apt: Archives directory archives/partial is missing. - Acquire (2: No such file or directory). The solution to this error was to also set Dir::Cache::archives to an empty path. I've updated your answer to include this (assuming somebody with higher rep approves the edit). – Blair Nov 21 '11 at 4:56
1  
Actually, setting these to blank paths doesn't work. I did so, and then installed and removed a package. Going to install it again I got Need to get 0 B/21.9 MB of archives indicating the presence of a cached version. Looking around it turns out they were cached in the root of the filesystem... not exactly what I wanted! Unless we're both reading the manpage for apt.conf wrong, either the manpage is wrong or there is a bug. I think I'll stick with the second method. – Blair Nov 21 '11 at 5:11
I've reported the Dir::Cache::Archive ""; bug at bugs.launchpad.net/apt/+bug/937951. When you've set that, do not run apt-get clean as it'll remove all files in the root directory (/). – Lekensteyn Feb 21 at 17:25
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.