8

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.

2 Answers2

9

In your script use rpm -q packagename:

if  rpm -q  vim-enhanced
then
  echo "Already installed vim-enhanced"
else
  echo "Install vim-enhanced"
fi
JJoao
  • 12,170
  • 1
  • 23
  • 45
  • 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. – AmadeusDrZaius Mar 26 '15 at 00:38
  • 1
    I'm happy it worked. Sometimes package names can be tricky. I wish package names were slightly more normalized... – JJoao Mar 26 '15 at 06:32
6

You can try:

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

or:

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

petry
  • 978