quickly find where a gem is installed
Sometimes you need to know where a gem is installed, or at least, where Ruby thinks a gem is installed, from within Ruby.
Use the find_by_name
method of Gem::Specification
:
[1] pry(main)> Gem::Specification::find_by_name('puppet').gem_dir
=> "/usr/lib/ruby/gems/1.9.1/gems/puppet-3.1.1"
Done!
Use find_by_name
without .gem_dir
for a lot more info.
Additional tip: from the commandline, gem which
might be what you need, but note that this will return the full path to the library, not the containing directory.
Written by Sam Halicke
Related protips
2 Responses
Why not use gem which pry
?
@hanjianwei gem which
returns results that include the full name of the gem (e.g. gem which bundler
returns a path ending in bundler.rb
where in this case i want only the directory name)
In this particular case, I want to know the gem's directory from inside Ruby, not necessarily from the command line. I use pry here to demonstrate interactively.