package snippets

Find the installation directory of a RubyGem package programmatically

Tagged ruby, rubygems, gem, path, package  Languages ruby

This snippet prints the full path to the Rails installation directory--the path is retrieved using the RubyGems API:

require 'rubygems'
# Specify version number
puts'rails', '=1.0.0').first.full_gem_path

Example output:


To find the directory where your gems are hiding, use:

gem env

There's also the gem which command:

$ gem which activesupport
(checking gem activesupport-2.3.2 for activesupport)