Why Are Gems Installed in a Directory With a Different Ruby Version Than I'M Running

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

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.

I'm using rbenv, so why are there two Gem paths on my system? (OS X Lion)

I think I figured out the answer to this question, so I'll post it.

Rbenv allows for a global and/or local version of ruby. So once a ruby is installed and managed via rbenv, you can declare it as a global ruby version used by your entire system.

Likewise, you can declare a local ruby version within a given directory (ex: a specific rails project).

The .gem file in your home path is used by the global ruby version, where as the one tucked away in the rbenv directory is used by the local ruby version.

Note, you can (for whatever reason) declare a local version that is the same as the global version. In that case, the local version will rely on the gem files that are in the deeper rbenv directory, instead of the ~/.gem directory.

How to fix Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5 while server starting

You better install Ruby 2.2.5 for compatibility. The Ruby version in your local machine is different from the one declared in Gemfile.

If you're using rvm:

rvm install 2.2.5
rvm use 2.2.5

else if you're using rbenv:

rbenv install 2.2.5
rbenv local 2.2.5

else if you can not change ruby version by rbenv,
read here

Bundle install runs from incorrect directory

Sounds like your app is already using bundler and you have a bundler-inside-bundler problem. Try this:

Bundler.with_clean_env do
puts `bundle install`
end

I'm guessing what's happening is that your outer bundler sets the BUNDLE_GEMFILE env variable to your app's Gemfile, and then your inner bundler ends up inheriting it.

two different versions of ruby referenced in error message?

This is because 1.9.1 is the Ruby C API version, which allows gems in that directory to be used across Ruby versions which comply with the same Ruby C API version (1.9.1–1.9.3 all use 1.9.1) without needing to recompile C extensions.



Related Topics



Leave a reply



Submit