apt-get update fetches and updates the package index. Because I'm used to this way of doing things, I was surprised to find that
yum update does all that and upgrades the system. This made me curious of how to update the package index without installing anything.
yum check-update by default doesn't pull down changes from remote repositories until
yum.conf's metadata_expire parameter has elapsed (default 90m). Apparently its purpose is "know if your machine had any updates that needed to be applied without running it interactively" so basically it's "check if any packages are update-able" not "refresh the list of packages that I could update to" as you'd expect.
So if you run
yum check-update and get this:
$ sudo yum check-update Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile packagename version repo
This means that check-update is not performing an update, like
apt-get update does.
You can see how long it will take before doing the "auto refresh" that all commands do underneath, by running this:
yum repolist enabled -v
yum clean expire-cache (or
yum clean all) first, then any future yum commands will auto-refresh the cache "when run." . Because future yum commands refresh the cache, this is in practice the same as
Or change the metadata_expire parameter of yum.conf to less than the default 90min, I guess.
yum makecache (from the other answers) which seems to remove the cache and pull down fresh copies right then. But it seems to take longer than
clean all (?) FWIW.
That is the command to update the local cache, hence
seems to be the command you are looking for, according to Working with Yum cache.
Normally you shouldn't need to run this command directly as yum already checks and refreshes metadata based on metadata_expire value in yum.conf, default being 6 hours.
However, there might be at least one use case, which is in an Ansible playbook, as you don't have a way in an Ansible playbook to only update the cache without installing any packages (See Ansible issues 33461 and 40068, which seems to be fixed in version 2.8, 46183). Ansible yum module requires a package name for 'update_cache: yes' option to have an effect. So, as an alternative 'command: yum makecache' can be used in the playbook.
dnf also has a makecache command, although it is also possible to force metadata synchronization with the --refresh switch.