Register now and start sharing your code snippets.
-->

Find the installation directory of a RubyGem package programmatically

Ruby posted about 1 year 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

Tagged ruby, rubygems