I recently ran into a bug in a script where I tried to do the following:

yum -y install another_package.x86_64 some_package.x86_64 && run_my_script

The script ran well on a newer CentOS, but when I tried to execute it on Cent OS 5, some_package.x86_64 was not available. But instead of erroring and stopping yum just printed the message:

No package some_package.x86_64 available.

How can I force yum to error in such situations (which IMO should be the default) to make my scripts more robust?

  • Build your script more rebust and check for return value of yum before going on. – frlan May 28 '15 at 10:22
  • 2
    @frlan That is the issue. yum happily returns 0 in this case. My script is already checking the return value before proceeding. Notice the &&? – pmr May 28 '15 at 10:29

As you've found, this behaviour changed between RHEL 5 and 6 (see https://bugzilla.redhat.com/show_bug.cgi?id=736694 for some discussion). From that link, checking the return code of yum info <pkg> should allow you to abort your script as required. Something like:

# Set a variable containing the packages to install:
pkgs_to_install='another_package.x86_64 some_package.x86_64'

# Loop over the packages in the list:
for pkg in ${pkgs_to_install}; do
  # Stop executing if at least one package isn't available:
  yum info ${pkg} >> /dev/null 2>&1 || exit

# Continue running your original script:
yum -y install ${pkgs_to_install} && run_my_script
  • 3
    OK, that helps and confirms that I'm not crazy to think that this should be the default. – pmr May 28 '15 at 10:57
  • 2
    helps well, the current yum behavior is quite unfriendly for script usage. – Karata Oct 25 '16 at 7:39

Per Bug 1274211, this has been fixed in yum-3.4.3-133.el7. However, you need to enable the strict mode.

The easiest way to do this for scripting purposes is via command-line switch:

yum -y --setopt=skip_missing_names_on_install=False install another_package.x86_64 some_package.x86_64 && run_my_script

However, you can also set it as a configuration option in your yum.conf:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.