How to accurately check if package is installed in yum?

181,963

Solution 1

Have you tried this?

$ yum list installed bind

Solution 2

There's a much easier way of issuing this query: rpm -qa | grep bind or rpm -q bind. The former is best if you're not completely sure of the package name.

Solution 3

Parsing the results of this command is the most complete answer. You'll need to know the exact package name.

yum info bind

Loaded plugins: refresh-packagekit, rhnplugin
This system is receiving updates from RHN Classic or RHN Satellite.
Installed Packages
Name        : bind
Arch        : x86_64
Epoch       : 32
Version     : 9.8.2
Release     : 0.17.rc1.el6_4.6
Size        : 7.3 M
Repo        : installed
From repo   : rhel-x86_64-workstation-6
Summary     : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server
URL         : http://www.isc.org/products/BIND/
License     : ISC
Description : BIND (Berkeley Internet Name Domain) is an implementation of the DNS
        : (Domain Name System) protocols. BIND includes a DNS server (named),
        : which resolves host names to IP addresses; a resolver library
        : (routines for applications to use when interfacing with DNS); and
        : tools for verifying that the DNS server is operating properly.

Solution 4

The best one liner I've come up with to do this (which is great for using quickly in scripts) is:

yum info <package_name> | grep Repo | awk '{ print $3 }'

For example: if I currently have git installed:

yum info git | grep Repo | awk '{ print $3 }'

This will return installed

If I currently don't have git installed that same previous command will return: base/7/x86_64 which is the current available installation for git

Share:
181,963

Related videos on Youtube

checksum
Author by

checksum

Updated on September 18, 2022

Comments

  • checksum
    checksum over 1 year

    I keep getting answers like:

    yum list installed | grep bind
    

    or

    rpm -qa | grep bind
    

    But that is not accurate as I'm getting a list of few other bind packages like these:

    bind-utils-9.8.2-0.17.rc1.el6_4.5.x86_64
    rpcbind-0.2.0-11.el6.x86_64
    bind-libs-9.8.2-0.17.rc1.el6_4.5.x86_64
    samba-winbind-3.6.9-151.el6.x86_64
    samba-winbind-clients-3.6.9-151.el6.x86_64
    ypbind-1.20.4-30.el6.x86_64
    

    That is not I wanted. Instead I would want to accurately check if bind core package has been installed. Eg. bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6

    I was hoping for something like:

    yum check installed bind
    

    But hopefully someone could shed the light.

  • checksum
    checksum over 10 years
    I'm getting Error: No matching Packages to list and $? returns 1, and when I tried yum list installed bind-libs, $? returns 0. Which should be correct so far. Can I safely conclude your command is accurately determine a package is installed? I did find out rpm -q bind just now. It it equavalent to your command also?
  • checksum
    checksum over 10 years
    Hmm, isn't that telling me bind is available/valid yum package instead of telling me if it is installed?
  • plasmid87
    plasmid87 over 10 years
    That's correct AFAIK, exit code 0 only if the package is installed.
  • Fred the Magic Wonder Dog
    Fred the Magic Wonder Dog over 10 years
    It's not obvious, but if installed is listed under the Repo tag, it's installed. Otherwise it would list the repo that it is available from.
  • Alex S
    Alex S over 7 years
    +1 for rpm -q $package I believe this is the fastest and solution, as doing anything with yum might force a cache update (usually slow).
  • Alex Angelico
    Alex Angelico over 7 years
    I think the correct command is with a wildcard: yum list installed bind*
  • rmmoul
    rmmoul about 7 years
    @AlejandroAngelico Though the RedHat documentation is very explicit about the necessity of escaping or quoting wildcard characters or globbed expressions, respectively.
  • Noah Sussman
    Noah Sussman over 6 years
    This is very slow compared to the rpm -q bind solution shown in John's answer. I don't think it's an optimal solution if it involves connecting to yum repos just to see what is installed locally.
  • Noah Sussman
    Noah Sussman over 6 years
    This solution (using rpm) should be the accepted answer as it returns a clean exit status and does not require calling out to a bunch of remote URLs as the yum solutions do.
  • Noah Sussman
    Noah Sussman over 6 years
    This results in connecting to remote yum repos when all I want is to see what's happening on my local machine.
  • Noah Sussman
    Noah Sussman over 6 years
    This results in connecting to remote yum repos when all I want is to see what's happening on my local machine.
  • Noah Sussman
    Noah Sussman over 6 years
    This is very slow compared to the rpm -q bind solution shown in John's answer.
  • domdambrogia
    domdambrogia over 6 years
    @NoahSussman to list all packages installed currently on your local machine you can use yum list installed. From there you can use the grep command to get a more precise answer for what you're looking for. Also if you want to check for a specific package you can add that to your command - Ex: php70w. yum list installed php70w would either list the info on the installed package or return No matching Packages to list
  • plasmid87
    plasmid87 over 6 years
    @NoahSussman You could try yum -C list installed bind to avoid network. This keeps all the plugins enabled (just in case you have anything exotic that affects lookups in yumdb) and also tells you the repo the package was installed from
  • plasmid87
    plasmid87 over 6 years
    @NoahSussman The exit codes for yum and rpm follow the same behavior in all examples I can think of (0 = installed, 1 = not installed / error) so it would be useful to know if you are seeing a different exit code. Please take a look at my response above regarding using the cache to avoid network access
  • Noah Sussman
    Noah Sussman about 6 years
    @plasmid87 wow I did not know about yum -C and that does change how I think about this problem. Thank you!
  • Noah Sussman
    Noah Sussman about 6 years
    @plasmid87 I did not know I could use yum -C to prevent yum from spending all that extra time contacting network hosts. Thank you, I now see how yum and rpm can be used interchangeably here!!
  • Noah Sussman
    Noah Sussman about 6 years
    Although perhaps using yum -C ... would be fast.
  • Inbar Rose
    Inbar Rose almost 6 years
    shouldn't this be not in ?
  • Gonçalo Peres
    Gonçalo Peres over 3 years
    rpm -q [Package-name] +1