dnf in a very similar way.What is YUM and its cache?
YUM is a tool that installs and updates software on CentOS. A cache is a store of saved copies kept for later use. YUM saves downloaded packages and lists of software in its cache so it can work faster. Over time the cache can grow large. Sometimes it also becomes old or broken, and then YUM shows odd errors.
When should you clean it?
- The disk is almost full.
- YUM says a package is damaged or cannot be found.
- YUM shows errors about repository data (a repository is an online store of software).
Steps
- Log in to your server over SSH as root. SSH lets you type commands on a server from a distance.
- See how much space the cache uses:
du -sh /var/cache/yum
This prints the size of the cache folder.
- Clean everything:
yum clean all
This removes saved packages, headers and list data. It does not remove software you installed.
- If you only want to remove downloaded packages, run:
yum clean packages
- To remove only the old software lists, run:
yum clean metadata
- Build a fresh cache:
yum makecache
This downloads new lists, so YUM is ready again.
- Test with a simple check:
yum check-update
This lists updates that are waiting. If it runs without errors, the cache is fine.
Still getting errors?
Try removing the cache folder contents by hand. Be careful with the path:
rm -rf /var/cache/yum/*
yum makecache
The first line deletes only cached files. Type it exactly, because a wrong path can delete other data. Take a backup first if you are unsure.
Quick recap
- The YUM cache stores downloads and software lists.
- Run
yum clean allto clear it. - Run
yum makecacheto rebuild it. - Cleaning does not remove installed software.
- Be careful with
rm -rf.