Clear Apt Cache on Ubuntu 20.04 - Best Method ?

Ubuntu users usually use the command apt-get to install software packages on their operating systems. Whenever they run the apt-get command, a .deb file will be saved on their local machine. This helps packages can be accessed locally, so when you need to reinstall them, it’s will speed up the installation process.

The downloaded deb files are located in /var/cache/apt/archives/. When you run the apt-get update and apt-get install command, the apt cache will be updated.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related APT tasks on Linux Systems.

In this context, we shall look into methods to clear the apt cache on your Ubuntu machine.

Why you need to remove the apt cache?

With time, the cache increases so much and it will take up a lot of memory. When you removing a software package then reinstall it, your operating system will search for the local apt cache, and the same version of the software will be reinstalled.

To list all the deb files, run the command:

$ ls /var/cache/apt/archives

In order to check how much disk space occupied by the apt cache, let's run the following command:

$ sudo du -sh /var/cache/apt/archives

How to Clear the system apt cache ?

To clear the apt cache on your Ubuntu machine, simply execute the following command:

$ sudo apt-get clean

Then, list all files in /var/cache/apt/archives again:

$ ls /var/cache/apt/archives

Now you will see that all of the deb files have already been removed.

[Need to Install Open Source Software on Debian system? We can help you. ]

This article covers the best method of listing and cleaning the apt cache on your Ubuntu system. Ubuntu users can clean Apt archive cache using sudo apt-get clean and sudo apt-get autoclean commands. The apt-get is a APT package handling utility or the command-line tool for handling packages. These commands clears out the local repository. The autoclean command only removes packages and files that are no longer in use. Ubuntu users can also do the same task from Synaptic package manager. Open Synaptic, go to Settings > Preferences > File tab. Select to delete packages that are no longer in use.

To clean Apt archive cache folder on Ubuntu, run:

$ sudo apt-get update
$ sudo apt-get clean
$ sudo apt-get autoclean

  • clean – clean 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/.
  • autoclean – 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.

Related Posts