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?
Asked
Active
Viewed 3.3k times
15
Blair
- 2,831
- 2
- 18
- 16
-
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. – jgomo3 Mar 30 '16 at 18:31
3 Answers
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.
Zanna
- 69,223
- 56
- 216
- 327
sagarchalise
- 23,668
- 12
- 72
- 85
-
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 04: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. – Blair Nov 21 '11 at 05:11
-
5I've reported the `Dir::Cache::Archive "";` bug at https://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
-
2According to the bug, `Dir::Cache::Archive` is the wrong configuration var; this should be `Dir::Cache::{src,}pkgcache`. – Jeremy Kerr Jul 04 '12 at 08:22
-
1
-
I confirm that Ubuntu 14.04, year 2016, still has the same problem. Tested on a container, and the root fills with the packages. Dir::Cache::Archive is not ignored. – jgomo3 Mar 30 '16 at 18:59
-
Reopened the bug. Feel free to chime in. https://bugs.launchpad.net/ubuntu/+source/apt/+bug/937951 – dragon Jan 07 '18 at 07:00
-
Ubuntu 18.04, just now: setting both entries (Dir::Cache + ::Archive) to "" works for me – OttoEisen Mar 29 '20 at 15:02
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
sourcejedi
- 448
- 3
- 15
-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$
Eliah Kagan
- 116,445
- 54
- 318
- 493
Victor
- 1
-
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 of `04autoclean` so that `APT::Clean-Installed` is set to `"true"`? – Eliah Kagan Jul 04 '12 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." – blueyed Jan 16 '15 at 22:56