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 Ibmi Media, 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.
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
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.
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