Jack Wallen shows you how to clean the caches for both the DNF and APT package managers, so you can solve package installation problems that arise from corrupt installation metadata.

Image: Jack Wallen
Both DNF and APT (the package managers for Red Hat and Ubuntu-based Linux distributions) store cached information to ensure the process of installing software is much faster and reliable. With these caches in place, neither package manager has to download the information every time you attempt to update, upgrade or install software.
But, there are times when that cache information can become outdated or corrupted. When that happens, you might find DNF of APT doesn't function properly.
What do you do? You clean the cache, which will delete all of that information so you have a clean slate.
How do you clean those caches? Let me show you.
SEE: Linux service control commands (TechRepublic Premium)
How to clean the cache for the DNF package manager
The best way to clean the DNF cache is by running the command:
sudo dnf clean dbcacheThis will remove all cache files generated from the repository metadata.
If that doesn't solve your problems, you can run a complete clean with the command:
sudo dnf clean allHow to clean the cache for the APT package manager
With the APT package manager, you can issue the command:
sudo apt-get cleanThis will remove the content from /var/cache/apt/archives (except for the lock file).
Another APT option is to run:
sudo apt-get autocleanThis only removes the packages that cannot be downloaded from repositories. In other words, if you downloaded a .deb package and installed it (as opposed to installing it from a remote repository), any file associated with that package will remain.
And that's all there is to cleaning the package manager caches for both Red Hat and Ubuntu-based distributions. You probably won't have to use these tools, but in case you do you now know how.
Subscribe to TechRepublic's How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
Open Source Weekly Newsletter
You don't want to miss our tips, tutorials, and commentary on the Linux OS and open source applications. Delivered Tuesdays
Sign up todayAlso see
Linux 101: How to hold packages back from getting upgraded with apt (TechRepublic)
Linux 101: Why file and directory names lack spaces (TechRepublic)
How to become a developer: A cheat sheet (TechRepublic)
Kubernetes: A cheat sheet (free PDF) (TechRepublic)
Could Microsoft be en route to dumping Windows in favor of Linux? (TechRepublic)
How open source-software transformed the business world (ZDNet)
Linux, Android, and more open source tech coverage (TechRepublic on Flipboard)