Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to clear APT cache in Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to clear the APT cache in Linux", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to clear APT cache in Linux.

How do I clear the APT cache? You just need to use this apt-get command option:

Sudo apt-get clean

However, cleaning up the APT cache is more than just running the above command.

What is APT caching? Why use it?

When you install a package using the apt-get or apt command (or install the DEB package in the Software Center), the APT package manager downloads the package and its dependencies in .deb format and saves it in the / var/cache/apt/archives folder.

When downloading, apt saves the deb package in the / var/cache/apt/archives/partial directory. When the deb package is fully downloaded, it will be moved to the / var/cache/apt/archives directory.

After downloading the package's deb files and their dependencies, your system will install the package from these deb files.

Now do you understand the purpose of caching? The system needs a place to store the package files before installing the package. If you understand the Linux directory structure, you will understand that / var/cache is the right place.

Why keep the cache after installing the package?

Downloaded deb files are not deleted from the directory immediately after installation is complete. If you delete a package and then reinstall it, your system will look for the package in the cache and get it from there instead of downloading it again (as long as the version in the cache is the same as the version in the remote repository).

That's a lot faster. You can try it yourself to see how long it takes for a program to be installed for the first time and then removed. You can use the time command to learn how long it takes to complete a command: time sudo apt install package_name.

I can't find anything about the cache retention policy, so I can't say how long Ubuntu will keep downloaded packages in the cache.

Should you clean the APT cache?

It's up to you. If you run out of disk space in your root directory, you can clean the APT cache to reclaim disk space. This is one of several ways to free disk space on Ubuntu.

Use the du command to check how much space the cache takes up:

Sometimes, this can take up hundreds of megabytes, and if you're running a server, this space can be critical.

How do I clean the APT cache?

If you want to clear the APT cache, there is a special command to do it. So don't delete the cache directory manually. Just use this command:

Sudo apt-get clean

This removes the contents of the / var/cache/apt/archives directory (except for the lock file). The following is the simulation deletion of the apt-get clean command:

There is another command about cleaning the APT cache:

Sudo apt-get autoclean

Unlike clean, autoclean deletes only those packages that cannot be downloaded from the repository. Suppose you have the package xyz installed. Its deb file remains in the cache. If there is a new xyz package in the repository now, the existing xyz package in the cache is out of date and useless. The autoclean option removes this useless package that can no longer be downloaded.

Is it safe to delete the apt cache?

Yes, it is completely safe to clear the cache created by APT. It will not adversely affect the performance of the system. Maybe if you reinstall the package, it will take longer to download, but that's it.

Again, use the apt-get clean command. It is faster and easier than manually deleting cache directories.

You can also use graphical tools like Stacer or Bleachbit to do this.

At this point, I believe you have a deeper understanding of "how to clear the APT cache in Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How to implement confirmation and submit by JavaScript

    This article is to share with you about how JavaScript implements the content submitted after confirmation. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look. Submit after confirmation and add the following code to the area

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report