11

On a current (2018-06) Debian sid, installing .deb packages via apt-get or aptitude or synaptic caches the downloaded packages in /var/cache/apt/archives:

# rm -f /var/cache/apt/archives/nano_*
# aptitude install nano
  [...]
# aptitude purge nano
  [...]
# ls /var/cache/apt/archives/nano_*

/var/cache/apt/archives/nano_2.9.7-1_amd64.deb

Using the frontend apt does not cache the downloaded files anymore:

# rm -f /var/cache/apt/archives/nano_*
# apt install nano
  [...]
# ls /var/cache/apt/archives/nano_*
ls: cannot access '/var/cache/apt/archives/nano_*':
      No such file or directory

So switching between two mutually exclusive sets of packages re-downloads everything. How can I change the settings of apt to keep the downloaded files?

1 Answer 1

15

Create a /etc/apt/apt.conf.d/01keep-debs file with the following content:

Binary::apt::APT::Keep-Downloaded-Packages "true";  

Your *.deb should be kept in /var/cache/apt/archives/* directory.

Or use it as option to keep the debs files for some selected packages.

 apt -o APT::Keep-Downloaded-Packages="true" install some_package.
4
  • 2
    Thank you. And FTR, this is option is not documented in the man-page for apt.conf, apt-config or apt_preferences. Jun 3, 2018 at 12:55
  • 1
    Thanks! The ready-to-copy-paste version could be echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' | tee -a /etc/apt/apt.conf.d/01-custom-local or if you need sudo then echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' | sudo tee -a /etc/apt/apt.conf.d/01-custom-local
    – mivk
    Feb 2, 2019 at 10:56
  • @GAD3R Can we have apt to cache those .deb files in a custom folder, say, ~/localrepo instead of /var/cache/apt/archives/?
    – vrgovinda
    Dec 21, 2021 at 10:59
  • if used in docker image, should truncate /etc/apt/apt.conf.d/docker-clean
    – 张馆长
    May 25, 2023 at 9:27

You must log in to answer this question.

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