# Rubygems: location of my gems

**URL:** <https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041>\
**Category:** Ruby\
**Created:** [January 4, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041 "2008-01-04T19:50:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [January 4, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041/1 "2008-01-04T19:50:13Z")

</div>

Hi,

Is there an easy way of finding the location of my installed gem  
programmatically.  
I need this to create an environment variable.

Thanks  
Nasir

---

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [January 4, 2008, 7:54pm UTC](https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041/2 "2008-01-04T19:54:53Z")

</div>

not in front of a computer but ‘gem env | grep -i gempath’ should come  
close  
to working

---

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [January 4, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041/3 "2008-01-04T20:01:21Z")

</div>

On 4 ene, 16:49, Nasir K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [Note: parts of this message were removed to make it a legal post.]
> 
> Hi,
> 
> Is there an easy way of finding the location of my installed gem  
> programmatically.  
> I need this to create an environment variable.

C:\Documents and Settings\Usuario\>irb  
irb(main):001:0\> require ‘rubygems’  
=\> true  
irb(main):002:0\> Gem.dir  
=\> “C:/Ruby/lib/ruby/gems/1.8”  
irb(main):003:0\>

HTH,

---

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [January 4, 2008, 8:21pm UTC](https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041/4 "2008-01-04T20:21:52Z")

</div>

gem which gemname

e.g.

raggi@mbk:~$ gem which hpricot  
(checking gem hpricot-0.6 for hpricot)  
/opt/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot.rb

---

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [January 4, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041/5 "2008-01-04T20:42:07Z")

</div>

On Fri, 04 Jan 2008 13:49:21 -0500, Nasir K. wrote:

> [Note: parts of this message were removed to make it a legal post.]
> 
> Hi,
> 
> Is there an easy way of finding the location of my installed gem  
> programmatically.  
> I need this to create an environment variable.
> 
> Thanks  
> Nasir

**FILE** will tell you the location of the file in which you use it. So  
when my SqlStatement gem is installed on Debian, the location of  
sqlstatement.rb is /var/lib/gems/1.8/gems/SqlStatement-1.0.2/lib/  
sqlstatement.rb, and I can find other paths in the directory tree by  
taking them relative to the known location of that file in my directory  
tree.

–Ken

---

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [January 4, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041/6 "2008-01-04T20:54:32Z")

</div>

On Jan 4, 2008, at 12:49 PM, Nasir K. wrote:

> Is there an easy way of finding the location of my installed gem  
> programmatically.

Sure:

gem\_spec = Gem::GemPathSearcher.new.find(require\_name)  
gem\_dir = File.join(gem\_spec.full\_gem\_path, gem\_spec.require\_path)

Hope that helps.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [January 4, 2008, 9:35pm UTC](https://www.ruby-forum.com/t/rubygems-location-of-my-gems/125041/7 "2008-01-04T21:35:37Z")

</div>

This is exactly what I was looking for. Thanks a lot.
