15

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?

1
  • 1
    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, 2016 at 18:31

3 Answers 3

10

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.

8
  • 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, 2011 at 4:56
  • 2
    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, 2011 at 5:11
  • 5
    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, 2012 at 17:25
  • 2
    According to the bug, Dir::Cache::Archive is the wrong configuration var; this should be Dir::Cache::{src,}pkgcache. Jul 4, 2012 at 8:22
  • 1
    Has this bug been fixed in a later version?
    – sep332
    Dec 20, 2013 at 21:46
0
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

-2

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$ 
2
  • 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"? Jul 4, 2012 at 10:47
  • 1
    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, 2015 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .