Skip to content

How to clear apt cache?

Linux’s apt-get utility makes it extremely easy for users to install just about any program with a single command. It also maintains a cache of the setup files for those programs should the user ever need to reinstall. 

The problem with this is that these caches can easily grow into hundreds of MBs if you’re installing many programs on your machine. If you’re running out of disk space, clearing the apt cache can instantly free up a bunch of space. 

In this article, we’re talking about the apt cache, what is it used for, and how can you clear it to save some space. 

Also read: 25 essential Linux Terminal commands


What is the apt cache?

It’s exactly what it sounds like, a collection of files downloaded using the apt utility stored for possible later use.

Every time you install a package using the apt-get command, the apt package manager downloads the program and its dependencies in a .deb file and stores them in the /var/cache/apt/archives directory.

How to clear apt cache? | Candid.Technology

Once the download is complete, your system installs the requested package using these files. The files themselves are kept if the user reinstalls the same version of the package they downloaded earlier. 

If the package version is different in the remote repository compared to the one in the cache, the new package will be downloaded and stored in the cache instead. 

As you can probably guess, this can hog up space rather quickly. If you’re running a server, clearing the apt cache should be a routine maintenance task on your list. 

Also read: How to install Steam on Linux?


How to clear the apt cache?

Now you could clear the apt cache by using the following command:

sudo apt-get clean
How to clear apt cache? | Candid.Technology

This will remove all the files saved in the /var/cache/apt/archives directory. There’s another command similar to clean as follows.

sudo apt-get autoclean
How to clear apt cache? | Candid.Technology

Instead of removing all packages, this command will only remove the packages that cannot be downloaded from the repositories. Meaning if the package that’s in the cache is outdated and a new version is available in the repository, it’ll be deleted.

Clearing out the apt cache is completely safe and will not impact your PC’s performance in any way. If you reinstall a package, you will have to wait a little bit longer, though. 

Also read: How to change MAC address on Windows and Linux?

Hello There!

If you like what you read, please support our publication by sharing it with your friends, family and colleagues. We're an ad-supported publication. So, if you're running an Adblocker, we humbly request you to whitelist us.







>