How to Disable APT Cache in Debian

In the Debian system, the packages are normally installed through the apt package manager, which installs the packages from the official Debian repository. The packages installed through apt are moved to the cache directory and are managed inside the location ‘/var/cache/apt/archives’. The reason to put these files in the cached directory is to ensure that the next time you install a dependent package of an existing package, it won’t install the same package again; instead, it will pick up the package from this location. As time passes, the package loses its worthiness and the time will come when it won’t require any more on the system. Thus, it is a good practice to disable the apt cache on the Debian system, as this will help free up some space.

Follow this article’s detailed guidelines to disable apt cache in Debian.

How to Disable APT Cache in Debian

An easy step-by-step instruction to disable apt cache in Debian is given below:

Step 1: First, you must create a 00clean-cache-dir file on the Debian system through nano editor:

sudo nano /etc/apt/apt.conf.d/00clean-cache-dir

Step 2: Within the file, you must add the following line:

DPkg::Post-Invoke {"/bin/rm -f /var/cache/apt/archives/*.deb || true";};

Step 3: Then save the clean cache file using “CTRL+X”, add “Y” and enter to exit.

Step 4: Then you have to create another file with “00disbale-cache-files” name:

sudo nano 00disable-cache-files

Step 5: Within this file, add the following lines:

Dir::Cache::srcpkgcache "";

Dir::Cache::pkgcache "";

Step 6: Save this file using Step 3.

This will disable the apt cache on the Debian system.

Step 7: Now the apt cache is disabled now, it’s better to empty the ‘/var/cache/apt/archives’ directory on Debian using the following command:

sudo rm -rf /var/cache/apt/archives

Step 8 (Optional): Alternatively, it’s a good practice if you run the following command to delete the cache:

sudo apt clean --dry-run

Step 9 (Optional): Further you can also remove the cache files and directories through the following command:

sudo apt clean

Step 10 (Optional): Let’s clean the system by removing the cache file and directories using the following command.

sudo apt autoclean


The apt cache on Debian can be disabled easily by creating a clean cache file inside the /etc/apt/apt.conf.d/ location. Then create another file with disable cache in the home location. Save both these files to disable the apt cache on Debian. It’s better to remove cache files and directories through “rm -rf” command or some apt commands that are optional but good practice if you run them on the terminal.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.