Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a good way to use Yum to test if something is installed (true of false) and then use that answer in a Bash script?

share|improve this question

It's faster to query using rpm instead.

if rpm -q somepackage &> /dev/null
share|improve this answer
You can make that even faster with rpm -q somepackage --nodigest --nosignatures. – mattdm Dec 13 '10 at 2:59

if you know a bit of python you could do it very easy - yum has pre/post filters that can be enabled you can even make your own plugin.

from shell just look for any lines that will be the output from your query.

pack = yum info package | wc -l

if [ "$pack" != '' ];


do something


do something else


share|improve this answer

I typically test for the results of the package, usually a file on the file-system that is installed. Something like:

[ ! -f /usr/bin/apg ] && yum -y install apg

This requires no RPM database lookup, so it's very light-weight.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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