Debian / Ubuntu Linux: Clear the Package Cache

last updated in Categories , , , , , , ,

Q. I’ve Debian Linux installed on 10 GB hard disk and noticed that /var/cache/apt/archives/ has lots of file taking my precious 1Gb disk space. Can I remove those file safely without causing any side effect on my setup?

A.If you are running out of disk space, you can try deleting the cache of package files. By default, the apt willkeep all the packages it has downloaded in case they’re needed in the future.


apt-get clean command clears out the local repository of retrieved package files. It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/. When APT is used as a dselect method, clean is run automatically. Those who do not use dselect will likely want to run apt-get clean from time to time to free up disk space.

To clear the cache from the command line, type the following:
$ sudo apt-get clean
# apt-get clean

There is also autoclean option. 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.


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

10 comment

  1. You can also use aptitude :

    aptitude clean : delete downloaded packages
    aptitude autoclean : delete old files from downloaded packages

    Note that I don’t really see the difference…

    1. Hi!
      I tried aptitude autoclean to delete old files but it returned:
      E: Could not open lock file /var/cache/apt/archives/lock – open (13: Permission denied)
      E: Unable to lock the download directory

      What does it mean? How to clean the traces left over?

  2. Tchetche, the difference is as Vivek describes in the article. autoclean automatically removes older packages that are unlikely to ever be needed. A plain old clean would just dump all the packages (manually, when you run it).

  3. Could you explain this ‘dselect’ method to us? I have a list of commonly installed apps and I pipe that list into new Debian installs, something like this I think:
    dpkg -dselect < packages.txt
    (I forget the exact syntax, so feel free to correct me). Then all those packages get installed, but (1) i have no idea what it really has done, and (2) how to I un-select those packages if, say, my list was wrong or i’ve changed m mind? I’ve always just been ‘forced’ to go with those options once they’re set even if not installed.

  4. Out of curiosity is there any gui method to do this?

    Note: I’m fully capable of using the terminal and will do so immediately to free up space but I know many that are more comfortable if all they have to do is point and click.

  5. Use aptitude. It has a GUI in which you can do point and click. Just invoke it with the command line:


  6. my computer doesnt let me download anything except .doc files. everything else, it says low disk space.
    so two questions: how do i delete stuff i dont need?
    and can i download straight to a memory stick? cuz it never gives me that option…

  7. Just to make it clearer:
    The autoclean parameter cleans only packages that are no longer available in the repositories we have in our sources.list, like packages that have been replaced by newer versions, or have been dropped from the repositories.

    Still, have a question? Get help on our forum!