Reputation: 34145
Ruby gems are installed into directories called after the last compatible version rather than specific release. How can I obtain that version?
For example for Ruby 2.3.3
, gems will be installed into 2.3.0
directory. How do I find out what that version is from a ruby interpreter?
Upvotes: 1
Views: 152
Reputation: 34145
Other answers that are kind of correct, but use paths. I tracked it down to:
Gem.ruby_api_version
Which will return the version on its own.
Upvotes: 2
Reputation: 14047
i get that same behavior with 2.3.1. here's one way of coming up with "2.3.0":
% ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
% ruby -e 'print Gem.user_dir'
/Users/kburnett/.gem/ruby/2.3.0
% ruby -e "print RbConfig::CONFIG['ruby_version']"
2.3.0
Upvotes: 0
Reputation: 168071
Gem.loaded_specs
will give you a hash of loaded gems. From that list, choose one gem:
Gem.loaded_specs["did_you_mean"]
# => {"did_you_mean"=>#<Gem::Specification:0x2abac1f4ecb8 did_you_mean-1.0.0>}
gem_dir
will give you the directory:
Gem.loaded_specs["did_you_mean"].gem_dir
# => ".../.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0"
In this case, I am using Ruby 2.3.3, and the gems are under the 2.3.0 directory.
Upvotes: 0