150

Debian's 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.

5 Answers 5

128

The check-update command will refresh the package index and check for available updates:

yum check-update
4
  • 7
    This command allows you to determine whether any updates are available for your installed packages. yum returns a list of all package updates from all repositories if any are available. apt-get update refresh index files but yum check-update does not.
    – SuB
    Apr 15, 2017 at 10:56
  • 4
    This doesn't work if yum has already been run recently, see some of the other answers for alternatives...
    – rogerdpack
    Jun 21, 2017 at 21:59
  • yum makecache is the right answer bcos check-update cannot be run until a certain amount of time has expired - about 90 mins or more ...
    – MarcoZen
    Jun 30, 2021 at 19:47
  • This command does not refresh the package index.
    – OrangeDog
    Jan 11 at 13:14
53

While yum check-update will check updates for installed packages, if it needs to be refreshed, so will most other commands.

The command that's strictly the equivalent of apt-get update is yum makecache ... however it's generally not recommended to run that directly, in yum.

7
  • 2
    I don't understand the first sentence. Can you rephrase maybe?
    – tshepang
    Feb 8, 2011 at 18:06
  • 18
    It means that other yum commands, e.g. yum upgrade will automatically run yum check-update if necessary. In other words, yum upgrade is basically the same as apt-get update; apt-get upgrade.
    – Mikel
    Feb 8, 2011 at 21:02
  • 4
    Why isn't it recommended to run yum makecache? It's listed in the man page and seems to work like apt-get update... also note that yum check-update doesn't always perform a refresh, see other answers, FWIW :)
    – rogerdpack
    Jun 7, 2019 at 16:23
  • 2
    @rogerdpack I've never heard a recommendation against yum makecache. I think that many people just say it's not worth running it; because, if the cache is old or expired, then yum updates the cache before any command that might modify the system. So yum makecache will make the next commands faster; but, if you forget it, then yum check-update will update the cache too, before it checks for updates.
    – Edwin Buck
    Feb 22, 2021 at 20:01
  • 2
    Because it will almost always do way more work than is required. There is a lot of logic in yum to keep the metadata updated automatically, without the user having to manually run a metadata sync command. Probably hundreds of lines of code since this question was asked. Even, yum clean expire-cache was probably added after this question was asked. Mar 2, 2021 at 19:00
41

Unfortunately 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

Work around:

use 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 apt-get update.

Or change the metadata_expire parameter of yum.conf to less than the default 90min, I guess.

Or run 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 xxx FWIW (?)

1
  • 5
    Not sure why this answer is languishing at the bottom. This seems like the obvious and simple answer.
    – cbmanica
    Aug 27, 2018 at 22:46
8

That is the command to update the local cache, hence

yum makecache

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.

1
  • 1
    This existing answer already mentions yum makecache; perhaps you could expand your answer to make it more useful, for example by explaining why yum makecache isn’t recommended, or what the dnf equivalent is. May 3, 2019 at 13:39
0

I'm using Centos Stream 9, and the simple command to pulling and updating is:

yum update

The command pulls all app updates and installs it automatically and it also does checks for available OS updates and attempts to update it, but it stops at the point of attempting to install the OS & Kernel updates to request for a confirmation before continuing, hence, you only need to allow it do the OS installation by typing Yes.

Things appears to be easier with Centos9 Stream 9 in the terminal for Redhat CentOS.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .