How to Clean the DNF and APT Caches in Linux

How to Clean the Dnf and Apt Caches in Linux

How to Clean the DNF and APT Caches in Linux

Home » News » How to Clean the DNF and APT Caches in Linux
Table of Contents

Each DNF and APT — the package deal managers for Crimson Hat and Ubuntu-based Linux distributions — retailer cached data to make sure the software program set up course of is way sooner and extra dependable. With these caches in place, neither package deal supervisor has to obtain the knowledge everytime you try and replace, improve, or set up software program.

However typically, that cache data can turn out to be outdated or corrupted. When that occurs, you may discover that the DNF of APT doesn’t perform correctly.

What do you do? You clear the cache, which can delete all of that data, so you’ve got a clear slate.

How do you clear these caches? Let me present you.

SEE: Debian vs Ubuntu: Which Linux Distro Matches Your Wants Finest? (roosho)

Tips on how to clear the cache for the DNF package deal supervisor

One of the simplest ways to scrub the DNF cache is by working the command:

sudo dnf clear dbcache

It will take away all cache information generated from the repository metadata.

If that doesn’t resolve your issues, you’ll be able to run a whole clear with the command:

sudo dnf clear all

SEE: Prime Instructions Linux Admins Have to Know (roosho Premium)

Tips on how to clear the cache for the APT package deal supervisor

With the APT package deal supervisor, you’ll be able to problem the command:

sudo apt-get clear

It will take away the content material from /var/cache/apt/archives (aside from the lock file).

One other APT possibility is to run:

sudo apt-get autoclean

This solely removes the packages that can’t be downloaded from repositories. In different phrases, should you downloaded a .deb package deal and put in it (versus putting in it from a distant repository), any file related to that package deal will stay.

And that’s all there may be to cleansing the package deal supervisor caches for each Crimson Hat and Ubuntu-based distributions. You most likely received’t have to make use of these instruments, however should you do, you know the way.

This text was initially revealed in June 2021. It was up to date by Antony Peyton in January 2025.

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
share this article.

Enjoying my articles?

Sign up to get new content delivered straight to your inbox.

Please enable JavaScript in your browser to complete this form.
Name