Find the installation directory of a RubyGem package programmatically
Ruby posted over 3 years ago by christian
This snippet prints the full path to the Rails installation directory—the path is retrieved using the RubyGems API:
1 require 'rubygems' 2 puts Gem.cache.search('rails').first.full_gem_path 3 # Specify version number 4 puts Gem.cache.search('rails', '=1.0.0').first.full_gem_path
Example output:
1 /usr/lib/ruby/gems/1.8/gems/rails-1.0.0
To find the directory where your gems are hiding, use:
1 gem env
There’s also the gem which command:
1 $ gem which activesupport 2 (checking gem activesupport-2.3.2 for activesupport) 3 /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/activesupport.rb