Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are gems installed in a directory with a different Ruby version than I’m running?

Tags:

ruby

rubygems

When I install a gem, it gets installed in a directory named 1.9.1, despite that not being the version of Ruby I have installed:

$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]

$ gem which rails
.../ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails.rb

Why does this happen? I have no other Ruby versions installed (and certainly not v1.9.1).

like image 900
Preacher Avatar asked Jun 15 '11 02:06

Preacher


People also ask

How do I install a specific version of a Ruby gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.

Where gem files are installed?

By default, binaries installed by gem will be placed into: /usr/local/lib/ruby/gems/3.1. 0/bin You may want to add this to your PATH.


2 Answers

Note that the following is also for all later Ruby versions as of this writing, not just 1.9.2.


Per the 1.9.2 release announcement:

Standard library is installed in /usr/local/lib/ruby/1.9.1

This version is a "library compatible version." Ruby 1.9.2 is almost 1.9.1 compatible, so the library is installed in the 1.9.1 directory.

Even though it is installed in a differently-numbered directory, it is using 1.9.2. RubyGems can show all the directories it’s using via gem env.

This ensures that a set of installed gems is only used by versions that they can actually run with (especially due to compiled C extensions), and that when upgrading to a newer, but “library compatible”, version, one doesn’t have to reinstall all gems.

like image 142
Dylan Markow Avatar answered Sep 21 '22 23:09

Dylan Markow


I believe it's because they share the same standard library.

There were some significant upgrades in the 1.9.2 core, but I don't think anything in the standard library was changed, so they share the same path. It's nothing to worry about, though — as you said, everything is working fine.

like image 34
coreyward Avatar answered Sep 20 '22 23:09

coreyward