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.


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

 rpm -q mypackage || rpm -i mypackage.rpm

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.


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).


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

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.