Make Debian Apt Cache .deb Files in /var/cache/apt/archives/

aptaptitudecachedebian

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?

Best Answer

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.
Related Question