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?
-
1I'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.– jgomo3Mar 30, 2016 at 18:31
3 Answers
According to the documentation you can add a config file to /etc/apt/apt.conf.d/
named no-cache
containing Dir::Cache "";
and Dir::Cache::archives "";
according to manual of apt.conf
. There is a bug report raising issues with this method, and I don't recommend it.
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 an rm
command just before apt quits.
-
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 setDir::Cache::archives
to an empty path. I've updated your answer to include this (assuming somebody with higher rep approves the edit).– BlairNov 21, 2011 at 4:56 -
2Actually, 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.– BlairNov 21, 2011 at 5:11 -
5I've reported the
Dir::Cache::Archive "";
bug at bugs.launchpad.net/apt/+bug/937951. When you've set that, do not runapt-get clean
as it'll remove all files in the root directory (/
). Feb 21, 2012 at 17:25 -
2According to the bug,
Dir::Cache::Archive
is the wrong configuration var; this should beDir::Cache::{src,}pkgcache
. Jul 4, 2012 at 8:22 -
1
echo 'APT::Keep-Downloaded-Packages "false";' \
> /etc/apt/apt.conf.d/01disable-cache
For more details, see: https://superuser.com/questions/1405001/why-does-apt-do-not-store-downloaded-packages-anymore
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$
-
2That 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 of04autoclean
so thatAPT::Clean-Installed
is set to"true"
? Jul 4, 2012 at 10:47 -
1This 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."– blueyedJan 16, 2015 at 22:56