Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I wish to install some RPM packages from a shell script. I want to ensure that each package is indeed installed, but I do not want to update a package that would already have an older version installed (to avoid going to deep into dependency resolution).

How can I achieve this in such a way, that a case where an older version is already installed will return without an error code, while in other cases of failures there will be an error code returned? This so that I am able to control the good execution of the script.

share|improve this question

you can install depending of package existence in the system by:

 rpm -q mypackage || rpm -i mypackage.rpm
share|improve this answer

Use the following command rpm -q mypackage && rpm -i mypackage.rpm. If querying for the rpm succeeds then installation of the rpm package will proceed. Else If the query fails then the installation will not proceed. However If you use || instead of &&, then despite of the previous command of querying the package fails, it will try to install the package, which anyway doesn't make sense.

share|improve this answer

What if you first test on whether the package in question is already installed and if not, you then install it. As you wrote you want to realize this within a Shell script, this would be some kind of if-clause.

Pseudo code:

if is_installed($package)
  return is_already_installed
  rpm -i $package
  return $?

The first part could be extended by another test on the currently installed version (e.g. for a final report of the script).

share|improve this answer

You may find rpm -q <package name> helpful, or even rpm -U for an upgrade.

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.