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.
SEE: Linux service control commands (TechRepublic Premium)
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.
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 dbcache
This 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 all
How to clean the cache for the APT package manager
With the APT package manager, you can issue the command:
sudo apt-get clean
This will remove the content from /var/cache/apt/archives (except for the lock file).
Another APT option is to run:
sudo apt-get autoclean
This 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.
Subscribe to the Developer Insider Newsletter
From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays