Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a gem is installed?

Tags:

ruby

gem

I installed data_mapper for a Sinatra project. Curious, why is it when I do gem install brew, I can $ which brew and get the path of its location and can't for data_mapper? This works for some gems and doesn't for others.

How do I verify a gem is installed properly? Would checking the version assure the gem is downloaded correctly?

like image 284
andy4thehuynh Avatar asked Mar 05 '14 23:03

andy4thehuynh


People also ask

How do you check if I have a gem installed?

Since your goal is to verify a gem is installed with the correct version, use gem list . You can limit to the specific gem by using gem list data_mapper . To verify that it's installed and working, you'll have to try to require the gem and then use it in your code.

How do I check if a ruby gem is installed?

To check if a specific version is installed, just add --version , e.g.: gem list -i compass --version 0.12.

Where is my gem installed?

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/. gem/ruby/1.9. 1 . The commands provided by the gems you installed will end up in ~/.

What is gem install command?

The install command installs local or remote gem into a gem repository. For gems with executables ruby installs a wrapper file into the executable directory by default.


1 Answers

General solution

To get the full list of gems that are installed:

gem list 

To test for a particular gem, you can use -i with a regex:

gem list -i "^gem_name$" 

(Credit to Timo in the comments for this technique.)

Particular solution for OP

If you can't find data_mapper, it may be that the gem name is different from what you expect.

Also, if you're just doing which brew to find brew, you aren't finding the gem called brew, you're finding the location of the brew executable. Try gem which brew instead.

EDIT:

If you're looking for data_mapper by doing which data_mapper, you probably won't find it. which is a unix program for finding unix executables, and data_mapper probably doesn't have one.

Since your goal is to verify a gem is installed with the correct version, use gem list. You can limit to the specific gem by using gem list data_mapper.

To verify that it's installed and working, you'll have to try to require the gem and then use it in your code.

like image 107
user513951 Avatar answered Oct 04 '22 13:10

user513951