Red Hat YUM cache documentation.
If you need a quick operator's move, start with yum clean all. It clears package files and repository metadata together, then let YUM rebuild what it needs on the next run. If you want a lighter touch, use yum clean expire-cache when repository freshness is the only doubt, since that action clears the time records that tell YUM when to revalidate metadata and mirrorlists Red Hat YUM cache documentation.
Need a broader server maintenance rhythm that doesn't turn into a midnight scramble? choose a scalable Linux distro if you're still standardizing fleets, then line up cache cleanup with your patch window instead of treating it as an emergency ritual. For a practical sizing sanity check while you're in the shell, the bytes to GB formula guide is handy when disk reports are still in raw units.
Red Hat YUM cache documentation Hivelocity YUM cache guide. On a busy host, that convenience turns into a storage problem fast, especially on systems that keep old repo data around longer than expected.
The first move is simple, and it is the one I trust when disk space is tight and I need a low-risk reset. Run yum clean all, then let YUM rebuild what it needs on the next transaction. That clears package files and repository data without touching installed software, so it fits routine maintenance instead of an emergency purge Red Hat YUM cache documentation.
A cache tree can include packages, metadata, headers, and time records for repository revalidation Hivelocity YUM cache guide. When a repo is stale, disabled, or noisy, that subtree is often the main offender. I have seen one stale repository directory grow until it was the only thing standing between a normal reboot and a storage incident.
Practical rule: if the host is healthy and you just need space back, a full cache clean is the fastest safe default.
| YUM cache item | What it is | Why it matters |
|---|---|---|
| Downloaded packages | Cached RPM files | Speeds repeat installs |
| Repository metadata | Package lists and repo data | Helps YUM resolve packages |
| Headers | Dependency-related package data | Supports dependency checks |
| Expire-cache timestamps | Revalidation timing records | Forces fresh repo checks |
If you are deciding how aggressive to be, tie the cleanup policy to the server role and the maintenance window. Build hosts, jump boxes, and app nodes do not all tolerate the same treatment, especially when the cache has become a convenience store instead of a throwaway layer. For broader distro planning, the internal RHEL family repository behavior guide helps keep repository behavior aligned with the right family, and the bytes-to-gigabytes conversion guide is useful when disk reports still come back in raw units.
When I set a cleanup policy, I also check what will refill the cache later. keepcache settings and update agents can undo your work without warning, so a one-time clean that is not paired with repo and automation settings only buys short-term relief. That is why cache cleanup works best as part of a maintenance habit, not as a panic response after the filesystem is already crowded.
yum clean all is the blunt instrument, but YUM gives you narrower tools when you don't want to wipe everything. yum clean packages removes downloaded RPMs and is the right call after a one-off install left a lot of local installer files behind. yum clean metadata is for stale repo information, especially when the package list looks out of date. yum clean headers targets the cached header data that supports dependency resolution Hivelocity YUM cache guide.
yum clean expire-cache is the lightest touch. Red Hat documents that it clears the time records for metadata and mirrorlists, which forces YUM to revalidate repository cache on the next use instead of deleting the stored files outright Red Hat YUM cache documentation. That matters when you want fresh repository checks without throwing away every cached artifact.
| Subcommand | Removes | Typical use case |
|---|---|---|
yum clean packages |
Cached RPM files | Free space after installs |
yum clean metadata |
Repo metadata cache | Repo freshness looks wrong |
yum clean headers |
Cached headers | Dependency data feels stale |
yum clean expire-cache |
Metadata and mirrorlist time records | Revalidate repos on next use |
yum clean all |
All cache categories | Broad reset, fastest cleanup |
yum clean dbcache |
Database cache | Resolve local cache oddities |
yum clean rpmdb |
RPM database cache | Troubleshoot package database concerns |
If you're managing a fleet, the decision is about blast radius, not command length. Narrower cleanup keeps troubleshooting signals around longer, which helps when you're trying to distinguish a cache problem from a repo problem. The same discipline applies when you're checking host state in the field, which is why the RHEL version check reference is useful before you standardize maintenance scripts.
scripting command execution across hosts is the clean way to keep the command path consistent.
A cleanup that breaks package resolution is a bad trade. I always verify in two passes, first disk, then functionality. Start with df -h for the mount and *`du -sh /var/cache/yum/`** before and after cleanup so you can see the actual space change, not just assume it happened.
Then test the package manager itself. yum repolist confirms the repos still show up, yum repoinfo shows per-repo metadata state, and yum install --assumeno against a known package proves resolution still works without making changes. If you did a broad cleanup, run yum makecache afterward so the metadata is rebuilt in a controlled way Red Hat YUM cache documentation.
| Check | What it tells you |
|---|---|
df -h |
Whether the filesystem reclaimed space |
du -sh /var/cache/yum/* |
Which repo cache shrank |
yum repolist |
Whether repositories still register |
yum repoinfo |
Whether repo metadata is fresh enough |
yum install --assumeno |
Whether package resolution still works |
If dependency resolution feels strange after a cleanup, the problem isn't always the cache. yum clean dbcache may be enough in a noisy environment, while a deeper package rebuild points to a different issue entirely. For those cases, I've found it useful to compare package errors against a general troubleshooting reference like the internal Python error handling guide, especially when automation wrapped the package run and hid the original failure.
Operational habit: verify the repo state before you close the ticket, not after the next failed install.

A one-off clean is remediation, not policy. If dnf-automatic or a nightly YUM job runs later, the cache can fill back up and leave you in the same spot. The durable fix is a cleanup policy that fits maintenance windows, then stays out of the way until the next planned run.
A weekly yum clean packages job is often enough when you want to keep metadata around for faster installs while removing downloaded RPMs. A separate yum clean expire-cache run before patch windows keeps repository revalidation predictable without discarding every bit of local state. On larger fleets, an automation layer like Ansible is easier to keep consistent than ad hoc admin memory, especially when the same cache policy has to land on many hosts Ansible cache management patterns.
keepcache=0 fits tight disks and short-lived package retention. keepcache=1 makes sense when local reinstallability or offline recovery matters more than reclaimed space. Pick the setting deliberately, because the host will keep following that policy long after the original cleanup is forgotten.
The cleaner model is simple. Cache cleanup belongs with patching, service restarts, and other scheduled maintenance, not with midnight firefighting. Teams that automate the rhythm instead of the command avoid the “we cleaned it yesterday, why is it full again” loop, which is the primary operational problem here. If you are lining up that work across a fleet, a runbook system such as Server Scheduler runbook automation guide helps keep cache jobs tied to the same maintenance window as the rest of the change. For teams that are also sorting out how much judgment to hand to tooling, the same discipline shows up in strategic AI implementation for teams, where policy and workflow matter more than a one-time command.
Not every server wants an aggressive cache purge. On bandwidth-constrained or air-gapped systems, deleting metadata can cost real time on the next repository check, and that's painful when connectivity is limited. On incident-response hosts, you may need a package immediately, so preserving local cache can be worth more than reclaimed disk.
Golden images are another place to be careful. If you want predictable bootstrapping and repeatable state, cache behavior should be baked into the image or baseline policy, not improvised later. The safe decision rule is simple, clean packages if disk is tight, clean metadata if freshness is in doubt, and avoid broad cleanup on a host that can't comfortably reach its repositories.
A host that needs offline recovery is not a good candidate for habitual cache deletion. The same applies to systems you can't revisit easily after a change, because the first failed reinstall is where bad cleanup policy shows up. Treat cache work like any other maintenance control, planned, documented, and aligned to the window you can support.
If you want this kind of maintenance to happen on schedule instead of after a 2am alert, Server Scheduler gives teams a simple way to line up server operations with maintenance windows and keep the work repeatable. Visit Server Scheduler to set up a cleaner operating rhythm for patching, cache hygiene, and the other jobs that shouldn't depend on memory at midnight.