问题
To clarify, I'm using rbenv
to manage my ruby versions. I was under the impression that binaries are managed as shims
in their respective ruby version directory.
Here is what my system shows when I run gem environment (I'm excluding the irrelevant parts):
- GEM PATHS:
- /Volumes/Data/nathan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1
- /Volumes/Data/nathan/.gem/ruby/1.9.1
Any reason for having two locations? Curious minds want to know.
回答1:
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.
回答2:
Keep in mind that ruby version managers like rbenv and rvm are relatively recent creations. Before they existed, an admin user would usually install ruby in a system-wide location like /usr/local. But non-admins needed a place to install their own gems, since they didn't have write permission under /usr/local . So the rubygems creators decided to add a secondary gem path in the current user's home directory, which would have a similar structure to the system location.
Here's an example of what the gem paths looked like in the old days:
- /usr/local/lib/ruby/gems/1.9.1
- /Users/kelvin/.gem/ruby/1.9.1
There still may be machines where ruby is installed like this, and you still have that recourse of the automatic secondary gem path. Of course you can also add more paths using the GEM_PATH environment variable, but the auto one is nice for handling the common case.
If you have admin rights, or you use a version manager, you can just ignore the ~/.gem dir as an artifact, a relic of the past if you will.
回答3:
- /Volumes/Data/nathan/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1
is from rbenv, so ruby looks for the gems rbenv installed.
- /Volumes/Data/nathan/.gem/ruby/1.9.1
Apparently, rbenv doesn't restrict itself to its own gems, but rather includes the gems from system ruby as well, but only the ones that are installed as user (via gem --user-install
).
来源:https://stackoverflow.com/questions/10432470/im-using-rbenv-so-why-are-there-two-gem-paths-on-my-system-os-x-lion