When I run yum install <X> where <X> has already been installed, yum exits with a return status of 1 and prints "Error: Nothing to do".

Aside from checking for this string in the output (which seems like a very shaky thing to base my script on), is there some way I can test whether the package already exists? Clearly, yum knows whether or not it already exists, since it's throwing that error, but how can I access that knowledge?

To add to this, some of the packages are downloaded by way of URLs, not package names, so checking yum list installed doesn't work.

  • 1
    yum knows by querying the rpm database. for example
    – Bratchley
    Commented Mar 25, 2015 at 18:09
  • @Bratchley Is there a way to get that name from a package url? Commented Mar 25, 2015 at 18:13
  • You should be able to give rpm a full URL to the RPM you're interested in. Example which will give you the package name. One note would be that it uses wget internally but seems to silently suppress errors.
    – Bratchley
    Commented Mar 25, 2015 at 18:17
  • 1
    @taliezin that's roughly equivalent to rpm -qa packageName except it's printed in a way that makes it look like yum output.
    – Bratchley
    Commented Mar 25, 2015 at 18:18
  • @Bratchley, sorry i saw the link later, but I deleted it.
    – taliezin
    Commented Mar 25, 2015 at 18:25

2 Answers 2


In your script use rpm -q packagename:

if  rpm -q  vim-enhanced
  echo "Already installed vim-enhanced"
  echo "Install vim-enhanced"
  • Thanks, this worked well. I had to manually fiddle with the package name for packages which were obtained through urls, but other than that, it went smoothly. Commented Mar 26, 2015 at 0:38
  • 1
    I'm happy it worked. Sometimes package names can be tricky. I wish package names were slightly more normalized...
    – JJoao
    Commented Mar 26, 2015 at 6:32

You can try:

#yum list installed | grep tmux
tmux.x86_64                      1.9a-5.fc21        @updates                    


#yum list installed tmux
Loaded plugins: langpacks
Installed Packages
tmux.x86_64                                                               1.9a-5.fc21                                                               @updates

Without grep you get some extra lines, but both outputs can be piped through some text editor according to your needs.

  • the disadvantage with this solution it hang if the list is huge somewho
    – mebada
    Commented Jun 2, 2019 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .