Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
I'm trying to do the same thing as I use many LXC to experiment and to keep my personal computer clean. One of those LXC is my apt-cacher-ng, but now I would like to prevent all other instances (including the "real" one) to keep an archives chace. – jgomo3 Mar 30 at 18:31
up vote 7 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
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 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";
share|improve this answer
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
This will only control how apt-get autoclean behaves. From apt-get(8): "The configuration option APT::Clean-Installed will prevent installed packages from being erased if it is set to off." – blueyed Jan 16 '15 at 22:56

Your Answer


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.