Debian / Ubuntu Linux: Clear the Package Cache

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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • Tchetche Jan 16, 2009 @ 11:20

    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…

    • himanshu Sep 20, 2015 @ 9:41

      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?

      • kattus Oct 4, 2015 @ 1:21

        Permission denied, you’ll have to run it as root.

  • Leaman Crews Jan 16, 2009 @ 15:36

    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).

  • lefty.crupps Jan 17, 2009 @ 15:57

    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.

  • Elias K Gardner Mar 12, 2009 @ 22:39

    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.

  • Maxei Apr 4, 2009 @ 17:19

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


  • bracha Feb 13, 2011 @ 7:41

    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…

  • evanp Jul 29, 2011 @ 1:32

    wow thankyou!! it works!

  • xXx Feb 7, 2013 @ 12:35

    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.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum