Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  How to Clear Cache in Ubuntu? Detailed Easy Steps
Top Scroll

How to Clear Cache in Ubuntu? Detailed Easy Steps

 3 min

Just like any other operating system, Ubuntu saves cache to increase speed and improve responsiveness. However, over time, the accumulated cache can lead to sluggish performance and waste valuable disk space. If you are experiencing storage problems or fixing network issues, clearing out the cache could be helpful.

In this article, we discuss different types of cache in Ubuntu and their effective methods of removal.

How to Clear Cache in Ubuntu?

Here are some forms of cache with their respective removal techniques.

1. Clear APT Cache

APT cache keeps package files in /var/cache/apt/archives/.

To clear all cached package files, follow the below command:

sudo apt clean

To clear only outdated packages, run the below command:

sudo apt autoclean

This allows for some space to be freed without any harm done to the installed software.

Related Read: Learn to clear the local DNS cache in Linux

2. Clear Thumbnail Cache in Ubuntu

The thumbnail cache can take unnecessary space and is located in the user’s home directory.

To clear the thumbnail cache, run:

rm -rf ~/.cache/thumbnails/*

This command will safely delete all the preview images.

3. Clear Application/User Cache

General application or user cache can be found in this directory: ~/.cache/. 

To remove all of the general application or user cache, run:

rm -rf ~/.cache/*

Tip: Make sure any running applications are closed before clearing to avoid problems.

4. Clearing DNS Cache in Ubuntu

When resolving network problems, you may want to clear the DNS cache in Ubuntu.

For systemd-resolved (Ubuntu 18.04+):  

sudo systemd-resolve --flush-caches  

You can verify whether your DNS cache in Ubuntu is cleared, with:

systemd-resolve --statistics  

For dnsmasq or nscd (if installed):

sudo /etc/init.d/dnsmasq restart  

or

sudo service nscd restart  

This process is also known as Ubuntu DNS flush or Ubuntu reset DNS cache.

GUI Applications to Clear Cache in Ubuntu

Of course, there are GUI applications such as

BleachBit: It’s a privacy and system cleaner application. You can install BleachBit on your Ubuntu server with:

sudo apt install bleachbit  

This allows you to choose the various cache files to be deleted, such as the browser, system, and package manager caches.

Automating Cache Clearing in Ubuntu

To automate the process of cleaning the caches, you can create a cron job:

crontab -e  

Add the following line to remove APT and thumbnail cache every week:

@weekly sudo apt clean && rm -rf ~/.cache/thumbnails/*  

If run without a prompt, you will need to set sudo permissions for the command to run safely.

Running Low on Disk Space?

In case you are still low on disk space after clearing your cache, you may want to consider the following:

1. Removing old kernels

To remove those, run the below command:

sudo apt autoremove --purge  

2. Checking large files

sudo du -sh /* 2>/dev/null

3. Using visualization tools like ncdu:  

sudo apt install ncdu

ncdu /
Conclusion

Regular cache maintenance in Ubuntu, be it APT, DNS, thumbnail, or user caches, will not only enhance system responsiveness and alleviate frequent problems but also improve overall efficiency and productivity. Terminal commands or GUI tools, such as BleachBit, can be used to maintain system cleanliness and optimization.

Similar Reads:
How to Clear Cache in iPhone: Complete Step-by-Step Guide
Clear Cache NPM: Easy Guide for Beginners

Frequently Asked Questions (FAQs)

How can I clear the thumbnail cache in Ubuntu?

You can clear it using
rm -rf ~/.cache/thumbnails/*

Are there any GUI tools to clear the cache in Ubuntu?

Yes. Tools like BleachBit let users clear their cache using a graphical interface.

My Ubuntu server’s disk space is still low after clearing the cache. What else can I do?

Remove old kernels, clear unneeded applications, or visually assess your disk usage with ncdu.

How can I automate the process of clearing the cache in Ubuntu?

Set up a cron job running on a daily or weekly basis that executes cache-clear commands. Furthermore, regular cache maintenance makes for a responsive Ubuntu system while minimizing the chances of sudden slowdowns.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.