ruby-on-railsrubyrubygems

How to programmatically get Ruby's standard library (or system gem) path?


I need to programmatically find the gem specifications path and the standard library (or a system gem) path of the Ruby installed on my system.

I can find the first easily:

puts Gem.default_specifications_dir
=> "/home/user/.rvm/rubies/ruby-x.y.z/lib/ruby/gems/x.y.a/specifications/default"

How can I find the latter? In my case, it should return one of the following (both are acceptable):

=> /home/user/.rvm/rubies/ruby-x.y.z/lib/ruby/x.y.a
=> /home/user/.rvm/rubies/ruby-x.y.z/lib/ruby/x.y.a/psych

Solution

  • The Gem lib has a constant: Gem::RUBYGEMS_DIR