yum clean all command actually suggests that you run
rm -rf /var/cache/yum:
» yum clean all
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-epel copr:copr.fedorainfracloud.org:jdoss:wireguard epel
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
There have been a few enhancements to the
yum clean all workings in the past (most notably https://bugzilla.redhat.com/show_bug.cgi?id=1357083) but you are absolutely right that there are edge cases where
yum clean all just doesn't do its job properly.
rm -rf /var/cache/yum, albeit nasty, does the trick every time.
The man page has a short message on cleaning untracked repos:
<...> Also note that untracked (no longer configured) repositories will not be automatically cleaned.
To purge the entire cache in one go, the easiest way is to delete the files manually. Depending on your cachedir configuration, this usually means treating any variables as shell wildcards and recursively removing matching directories. For example, if your cachedir is /var/cache/yum/$basearch/$releasever, then the whole /var/cache/yum directory has to be removed. If you do this, yum will rebuild the cache as required the next time it is run (this may take a while).
Regarding the last point about rebuilding taking a long time, you might want to follow
rm -rf /var/cache/yum with
&& yum makecache to properly recreate the directories and avoid long waits on the next yum invocation. Note the difference between
makecache fast though, most don't really know the difference.
yum makecache fast only makes sure the repos are current.
yum makecache actually downloads the metadata.