I have 2 systems running Debian at home and I am trying to minimize the bandwidth use while upgrading the packages. How can I increase the size limit of the cache, so that I could just copy the packages over LAN? (currently they get removed too quickly)

  • 1
    What is the output of apt-config dump | grep -i clean? – enzotib Oct 4 '11 at 16:42
  • Hi @enzotib, I get nothing: grzes:/home/ga# apt-config dump | grep -i clean? grzes:/home/ga# – Grzenio Oct 5 '11 at 6:57
  • 1
    The question mark was not part of the command :) – enzotib Oct 5 '11 at 6:59
  • 1
    Heh :) Without the question mark I get the following: APT::Periodic::AutocleanInterval "0"; – Grzenio Oct 6 '11 at 9:16
  • It appears that APT::Archives::MinAge (default of 2) should be enough if you tend to do upgrades on both machines at similar times. – Peter Cordes Feb 4 '15 at 2:44

The size limit is controlled by the apt option APT::Periodic::MaxSize. You can display your current value using the following command:

apt-config dump | grep Periodic

To set the size, edit or create the file /etc/apt/apt.conf.d/99local-archive and any of the following lines:

APT::Periodic::MaxSize "<size_in_MiB>";
APT::Periodic::MaxAge "<days>";
APT::Periodic::MinAge "<days>";

See /etc/cron.daily/apt for comments on available options, and the transition from APT::Archives::*. (Ubuntu 14.04 ships /etc/apt/apt.conf.d/20archive which sets APT::Archives::MaxSize. When they transition to APT::Periodic in that file, it will matter that you put your local changes in a file with a higher number.)

This sets the maximum size of the cache in MiB. If the cache is bigger, cached package files are deleted until the size requirement is met (the biggest packages will be deleted first).

Make sure to do this on all machines that mount the directory.

  • It's now APT::Archives::MaxSize, not ...Periodic.... (Ubuntu 14.04, apt 1.0.1ubuntu2.6) There's also ...::MinAge and ...::MaxAge (in days, I guess since the defaults are 2 and 30). I assume MinAge is a grace period for exceeding MaxSize. – Peter Cordes Feb 4 '15 at 2:32
  • Also note that if either machine does apt-get autoclean, any package that doesn't show up in its list as available will be removed. ` – Peter Cordes Feb 4 '15 at 2:36
  • Also, Ubuntu ships /etc/apt/apt.conf.d/20archive, (dunno about Debian). Files are processed in order, with later ones able to override earlier ones. (I checked with apt-config dump.) You should put your changed in /etc/apt/apt.conf.d/99local-archive. – Peter Cordes Feb 4 '15 at 3:58
  • hmm, I wonder if you can set Dir::Cache::archives to an absolute path (like /net/tesla/var/cache/apt/archives/), instead of the default relative path (archives/). Might be easier on a laptop that isn't always kept at home, easier than manually mounting over your local /var/cache/apt/archives/. – Peter Cordes Feb 4 '15 at 4:05
  • 1
    Oops, ignore my first comment. lists.debian.org/deity/2014/03/msg00182.html and /etc/cron.daily/apt indicate that APT::Periodic is the new one, and Archives is the deprecated one. I guess the cron job is the only thing to ever prune the cache, since the size/age stuff is now specific to it. – Peter Cordes Feb 4 '15 at 5:18

You should consider using a separate caching proxy for your apt instances. apt-proxy is one tool you could try. Let that do the caching and prune the individual apt archives more aggressively.

  • For just 2 machines? Nah just NFS mount /var/cache/apt/archives, esp. now that Marco has identified the right setting to increase the max size. – Peter Cordes Feb 4 '15 at 2:27

To set the cache size for apt, you need to edit apt.conf. You can get information on how to configure it in man apt.conf. If it is not already present create it in /etc/apt/apt.conf or you may need to edit /etc/apt/apt.conf.d/70debconf file, please refer specific version's documentation.

Debian provides Cache-Limit option in APT Group in apt.conf. You can experiment with it.

man apt.conf says,

              APT  uses  a  fixed  size  memory mapped cache file to store the
              'available' information. This sets the size of that cache. 

So you need to put following line in apt.conf.

APT::Cache-Limit "cache_size" Put appropriate cache size in place.

  • 3
    Cache-Limit controls the cache in main memory used at runtime, not the disk cache in /var/cache/apt/archives. – Marco Sep 5 '13 at 10:30
  • Yup, this answer is unfortunately wrong. I guess grzenio accepted it without testing (since it's non-trivial to test.) – Peter Cordes Feb 4 '15 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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