May 23, 2012
tom

Checking if a ruby gem is installed from bash script

Question

I need to, from a bash script, check to see if certain Ruby gems are installed .

I thought I could do something like

if ! gem list <name>; then do_stuff; fi

but testing on the command line using echo $? shows that gem list <name> returns 0 regardless of if name is actually found.

Does this mean I have to use grep to filter the output of gem list, or is there a better way I can check to see if a gem is installed?

Asked by Lee Lowder

Answer

gem list <name> -i will return the string true if the gem is installed and false otherwise. Also, the return codes are what you would expect.

For more informations, see gem help list.

Answered by SvenW

Related posts:

  1. Ruby MySQL/Gem issue Windows 7
  2. Phusion Passenger Nginx module installer can not find rack gem installed
  3. How is a Ruby Gem usually updated (from developers to my applications)?
  4. Rails: missing gem roxml
  5. gem vs apt-get in a server environment

Leave a comment