I generally have bad internet connection and it makes trouble when apt-get install an-app. So I am backing up .deb files in /var/cache/apt/archives regularly and copying into the same folder when I do new installation. This way, dependencies of applications with the exception of already installed ones are also backing up. And I found this command to download all dependencies of an app including the ones that already installed on my system:

apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-pre-depends <appname> | grep "^\w" | sort -u)
apt-get download <appname>

I use this because some dependencies of app may not be installed on a new system.

But in this condition if I upgrade any application, I also store its old .deb file on my disk. And these files becomes garbage. I need to clean this garbage from cache folder. So my question is:

Is there any way of mirroring the repository files for only specific applications and its all dependencies (and only latest versions)? Or mirror the debian repository for specific apps only using apt-mirror or something similar?


Finally I resolved with these steps:

  1. Make backup of /var/cache/apt directory (not only /var/cache/apt/archives).

  2. set APT::Clean-Installed property to false in apt.conf file. to do this make a .conf file in /etc/apt/apt.conf.d and add APT::Clean-Installed "false"; line. For example:

    $ sudo touch /etc/apt/apt.conf.d/custom.conf
    $ sudo echo "APT::Clean-Installed "false";" > /etc/apt/apt.conf.d/custom.conf
  3. To clean cache without installed apps' files:

    $ sudo apt-get autoclean

I got this from man 8 apt-get:

autoclean (and the auto-clean alias since 1.1)
Like clean, autoclean clears out the local repository of retrieved package files. The difference is that it only removes package files that can no longer be downloaded, and are largely useless. This allows a cache to be maintained over a long period without it growing out of control. The configuration option APT::Clean-Installed will prevent installed packages from being erased if it is set to off.

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.