25 C
Jaipur
Friday, October 23, 2020

How to Clear Apt Cache on Ubuntu and Free Crucial Disk Space

Must read

huawei: Huawei ekes out third-quarter revenue growth as US restrictions bite – Latest News

Huawei Technologies Co Ltd eked out a gain in third-quarter revenue as the impact of the COVID-19 pandemic added to supply-chain difficulties brought about...

MEE Audio launches new range of Bluetooth audio accessories

MEE Audio has released a new range of audio products at different price points. There’s a new ‘MEE Audio Connect

Accenture along with SAP aims to take businesses into cloud-based open industry solutions

Accenture has announced it will be working side-by-side with SAP to help companies change their business operations with industry-specific solutions based on SAP’s...

huawei: Italy vetoes 5G deal between Fastweb and China’s Huawei: Sources – Latest News

Italy has prevented telecoms group Fastweb from signing a supply deal with Huawei for its 5G core network, two sources close to the matter...

How do you clear the apt cache? You simply use this apt-get command option:

sudo apt-get clean

But there is more to cleaning apt cache than just running the above command.

In this tutorial, I’ll explain what is apt cache, why is it used, why you would want to clean it and what other things you should know about purging apt cache.

I am going to use Ubuntu here for reference but since this is about apt, it is applicable to Debian and other Debian and Ubuntu-based distributions like Linux Mint, Deepin and more.

What is apt cache? Why is it used?

When you install a package using apt-get or apt command (or DEB packages in the software center), the apt package manager downloads the package and its dependencies in .deb format and keeps it in /var/cache/apt/archives folder.

While downloading, apt keeps the deb package in /var/cache/apt/archives/partial directory. When the deb package is downloaded completely, it is moved out to /var/cache/apt/archives directory.

Once the deb files for the package and its dependencies are downloaded, your system installs the package from these deb files.

Now you see the use of cache? The system needs a place to keep the package files somewhere before installing them. If you are aware of the Linux directory structure, you would understand that /var/cache is the appropriate here.

Why keep the cache after installing the package?

The downloaded deb files are not removed from the directory immediately after the installation is completed. If you remove a package and reinstall it, your system will look for the package in the cache and get it from here instead of downloading it again (as long as the package version in the cache is the same as the version in remote repository).

This is much quicker. You can try this on your own and see how long a program takes to install the first time, remove it and install it again. You can use the time command to find out how long does it take to complete a command: time sudo apt install package_name.

I couldn’t find anything concrete on the cache retention policy so I cannot say how long does Ubuntu keep the downloaded packages in the cache.

Should you clean apt cache?

It depends on you. If you are running out of disk space on root, you could clean apt cache and reclaim the disk space. It is one of the several ways to free up disk space on Ubuntu.

Check how much space the cache takes with the du command:

Apt Cache Archive Size

Sometime this could go in 100s of MB and this space could be crucial if you are running a server.

How to clean apt cache?

If you want to clear the apt cache, there is a dedicated command to do that. So don’t go about manually deleting the cache directory. Simply use this command:

sudo apt-get clean

This will remove the content of the /var/cache/apt/archives directory (except the lock file). Here’s a dry run (simulation) of what the apt-get clean command deletes:

Apt Get Clean Ubuntu

There is another command that deals with cleaning the apt cache:

sudo apt-get autoclean

Unlike clean, autoclean only removes the packages that are not possible to download from the repositories.

Suppose you installed package xyz. Its deb files remain in the cache. If there is now a new version of xyz package available in the repository, this existing xyz package in the cache is now outdated and useless. The autoclean option will delete such useless packages that cannot be downloaded anymore.

Is it safe to delete apt cache?

Clear Apt Cache

Yes. It is completely safe to clear the cache created by apt. It won’t negatively impact the performance of the system. Maybe if you reinstall the package it will take a bit longer to download but that’s about it.

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

You may also use graphical tools like Stacer or Bleachbit for this purpose.

Conclusion

At the time of writing this article, there is no built-in option with the newer apt command. However, keeping backward compatibility, apt clean can still be run (which should be running apt-get clean underneath it). Please refer to this article to know the difference between apt and apt-get.

I hope you find this explanation about apt cache interesting. It is not something essential but knowing this little things make you more knowledgeable about your Linux system.

I welcome your feedback and suggestions in the comment section.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

huawei: Huawei ekes out third-quarter revenue growth as US restrictions bite – Latest News

Huawei Technologies Co Ltd eked out a gain in third-quarter revenue as the impact of the COVID-19 pandemic added to supply-chain difficulties brought about...

MEE Audio launches new range of Bluetooth audio accessories

MEE Audio has released a new range of audio products at different price points. There’s a new ‘MEE Audio Connect

Accenture along with SAP aims to take businesses into cloud-based open industry solutions

Accenture has announced it will be working side-by-side with SAP to help companies change their business operations with industry-specific solutions based on SAP’s...

huawei: Italy vetoes 5G deal between Fastweb and China’s Huawei: Sources – Latest News

Italy has prevented telecoms group Fastweb from signing a supply deal with Huawei for its 5G core network, two sources close to the matter...

huawei: Huawei reports 9.9% revenue growth in first 3 quarters of 2020 – Latest News

Huawei on Friday said that it generated a revenue of 671.3 billion yuan ($98.57 billion) in the first three quarters of this year, an...