Command Linux

How Do I Clear apt-get Cache

The apt clean command is used to free up disk space as part of scheduled and regular maintenance. This command removes the local repository of package files downloaded from /var/cache/apt/archives/ except lock files and partial folders.

This article will show you how to clear the apt-cache on Ubuntu. This process applies to other Debian, Ubuntu-based distributions such as Deepin, Linux, Mint, and more.

We aim to provide a brief on apt clean as many people look for Ubuntu clear cache methods to clean up their system.

What is Apt-Cache?

When we install a package with the help of apt command, apt-get, or DEB package in the software center, the appropriate package manager will find its dependencies and package.deb format and keep it in /var/cache/apt/archives.

When we download the deb package, the system moves it to /var/cache/apt/archives. While downloading this package, apt kept this package in /var/cache/apt/archives/partial directory.

When we download deb files and dependencies of a package, our system automatically installs the package from all these deb files.

The deb files we download are not immediately removed from the directory once the installation is complete. Whenever we remove a package and reinstall it for whatever reason, the system looks for it in the cache.

Through this, instead of downloading it back, the system gets it from here itself. It’s possible to do this if the package version in the cache matches the package version in the remote repository.

This process is relatively quick. We can see that if we download a new package, remove it, and install it again, we can see how fast it downloads the second time from the time command.

Is It Important to Clear Apt-Get Cache?

  • We can understand this through an example of how the du command can sometimes go to 100s MB, and if we use a server, then this space can be useful.
  • Whether we should clear our cache or not depends on us.
  • If we are running out of disk space on the root, we should clear the appropriate cache. In short, sometimes, we need to reclaim and free disk space.
  • We can achieve the freeing up of disk space on Ubuntu in this way.

How Do I Clear Apt-Get Cache?

If we want to remove apt-cache, then we should not remove the cache directory manually. There is a separate dedicated command for it so let’s clear cache in Ubuntu using terminal:

$ sudo apt-get clean

In other words, this command deletes all contents of the /var/cache/apt/archives directory except the lock file. It is a simulation of the effect of the apt-get clean command.

There is another command to be as handy as this one for clearing cache.

$ sudo apt-get auto-clean

The auto-clean command removes only those packages which are not possible to download from the repository.

If we install any new package “A” in the system, its deb files remain in the cache. After some time, if a new version of “A” is available in the repository, the existing package becomes useless and outdated.

The auto-clean option removes useless packages that we cannot download back.

Conclusion

If we clean the obsolete deb packages, then we have to use apt-get auto clean. It removes all those files which are mainly useless and which cannot be downloaded back. We hope that from this article explained by us, you will know very well why and how to use apt-cache. This small thing increases our knowledge of Linux.

Related Articles

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Back to top button