Score:2

Safe way to clear all packages from yum cache?

us flag

I know that yum clean all doesn't necessarily clear all the package files. I know from "Maybe you want: rm -rf /var/cache/yum" that I might have to, good grief, bluntly clear all of /var/cache/yum. But I've just discovered that I very definitely do not want to clear all of /var/cache/yum, because evidently the record of which packages are installed is also kept down in there somewhere. Without certain files in /var/cache/yum, rpm -qa seems to print nothing.

So is there a simple rule for which other files underneath /var/cache/yum can be manually deleted, to save space by deleting package files that aren't needed (or can be easily redownloaded), but preserving the installation state of the system?

It's possible I'm completely mistaken on one or more of my assumptions here. Corrections welcome if so.

Update: I'm skipping some details here, but copying all of /var/cache/yum from the system that had it to the system that didn't did not fix rpm -qa (it's still printing nothing), so it's looking like one of my assumptions is flawed, and the system's installed state is kept somewhere under /var other than /var/cache/yum.

Update 2: I was wrong in one of my assumptions. As I eventually discovered, and as @shodanshok points out in an answer, the database of packages currently installed is down under /var/lib/rpm, not /var/cache/yum. So clearing all of /var/cache/yum should be safe.

Score:6
ca flag

Running yum clean all is generally sufficient for all intents and purposes, as it will only leave so little used space behind. The exception is when you disabled a repo before running yum clean all, forbidding yum from clearing that repo cache.

Anyway, deleting /var/cache/yum should have no bad effects, especially because RPM database is located under /var/lib/rpm rather that under /var/cache.

Score:0
cn flag

A Red Hat box with no rpm packages installed at all is broken.

First, confirm this is a host that should have a real rpm database. Not some weird container or chroot or other stripped down thing. Determine if the system is supposed to get updates by yum update. And check yum history for if the most recent yum commands are recorded. yum would not get into this state by itself, it would refuse to remove protected packages.

Having a functional system, but nothing in rpm queries, implies someone did something very unsafe to rpm. Such as removed the rpm database without erasing packages. Will be a real mess to clean up. As discussed, removing yum caches will not do this.

Consider reinstalling a new host from the installer. Restore data. Advantages of this clean start include starting with a known good rpm system. And possibly you can take the opportunity to do major software upgrades.

Or, it may be possible to recover from a corrupted rpm database. Assuming any database still exists. Only do this if you cannot restore from backup, and understand which database backend your rpm is using. Back up the host, including rpm db, prior to attempting. The host would need to be of some value to you, if doing surgery on its package database is easier than a reinstall.

Steve Summit avatar
us flag
Thanks for all that. I am in fact working on an installation procedure. The "corrupted" system was the interim result of that installation procedure — a virgin system, as it were, that gets blown away multiple times per day as I refine the installation procedure. So there's no need to "recover" anything (a missing rpm database, or otherwise), because clean reinstalls (with a fixed or at least better installation procedure) are absolutely the order of the day!
Steve Summit avatar
us flag
That installation procedure wasn't properly populating `/var/lib/rpm`, and that was precisely the problem. I was mistakenly distracted by `/var/cache/yum`.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.