How to Clear Apt Cache

Channel: Linux
Abstract: the system doesn't need to go through the network. Downloaded package are locally cached in /var/cache/apt/archives/. Each time when you run apt-get u

When you install packages in Debian/Ubuntu using the apt-get command, a copy of the .deb file is locally stored. This helps in case you need to reinstall them after removal, then packages can be accessed locally (in another way called cache). Each time when you reinstall, the system doesn't need to go through the network.

Downloaded package are locally cached in /var/cache/apt/archives/. Each time when you run apt-get update and apt-get install command, the apt cache is updated.

In this tutorial we learn how to clear apt cache on Debian and Ubuntu systems.

How to Clear Windows Update Cache (...

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

How to Clear Windows Update Cache (Windows 10)

Note: If you are using apt command, instead of apt-get command then this cache is automatically deleted in the new OS versions.

Reason to clean Apt cache
  1. Sometimes you may need to free disk space and reclaim it.
  2. Removing a package and reinstalling it, the system will look on the cache and you will get the same version of the software.

To list .deb file which stored in cache, type:

$ ls /var/cache/apt/archives/
List of apt cache files

To check the disk utilized by the cache by running the following command. I

$ sudo du -sch /var/cache/apt/archives/
Disk utilization by apt cache

In my case, it is more than 340 MB.

To clean apt cache use apt clean command, which removes everything (except the lock file) from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.

You can also simulate or dry run to see what actually happens when you clean the apt cache, type:

$ sudo apt-get clean --dry-run
Dry run of apt clean

It display which directory content will be removed.

Its safe to run apt-get clean command as its only removes a copy of .deb files. Next time when you run apt-get install it can fetch packages from mirror.

Finally to clean the apt cache simply run following command.

$ sudo apt-get clean
Conclusion

If you intention is to clear only the obsolete deb packages, use apt-get autoclean. This will removes package files that can no longer be downloaded, and are largely useless.

In this tutorial, we learned how to clean the apt cache in Debian and Ubuntu. Your comments and suggestions are highly recommended. Thank you.

Ref From: linoxide
Channels:

Related articles