Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 5 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.

share|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
1  
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 '12 at 17:25
    
According to the bug, Dir::Cache::Archive is the wrong configuration var; this should be Dir::Cache::{src,}pkgcache. –  Jeremy Kerr Jul 4 '12 at 8:22
    
Has this bug been fixed in a later version? –  sep332 Dec 20 '13 at 21:46

I think that what you are looking for is:

/etc/apt/apt.conf.d$ cat 04autoclean
APT::Clean-Installed "true";
/etc/apt/apt.conf.d$ 
share|improve this answer
2  
That command does not change anything--it just shows the contents of 04autoclean (when run in the /etc/apt/apt.conf.d directory). Are you saying Blair should change the contents of 04autoclean so that APT::Clean-Installed is set to "true"? –  Eliah Kagan Jul 4 '12 at 10:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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