Ruby gem 环境的 shell 路径不同于 shell 路径

Ruby gem environment's shell path different than the shell path

我已经安装了 Ruby and gem and use bundle。但是当我尝试从 Gemfile 安装时它失败了:

> which bundle                                                                                                                                                                              
/opt/local/bin/bundle
> bundle install                                                                                                                                                                            
Your Ruby version is 2.1.7, but your Gemfile specified 2.1.3

指定的 Gemfile ruby '2.1.3' 这是我在本地安装的:

> rbenv local
2.1.3
> rbenv global
2.1.3
> ruby -v                                                                                                                                                                                   
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin14.0]
> which ruby                                                                                                                                                                                
/path/to/home/.rbenv/shims/ruby

到目前为止这一切似乎都很好。系统ruby是2.1.7.

我的 shell 搜索路径 $PATH 以垫片 /path/to/home/.rbenv/shims: 开始。但是,当我转储 gem environment 时,shell 路径在 垫片之前有更多条目 ,其中一个包含系统 ruby:

> echo $PATH                                                                                                                                                                                
/path/to/home/.rbenv/shims: ...
> which gem                                                                                                                                                                                 
/path/to/home/.rbenv/shims/gem
> gem environment                                                                                                                                                                           
  ...
  - SHELL PATH:
     - /path/to/home/.rbenv/versions/2.1.3/bin
     - /opt/local/bin                <- contains system ruby 2.1.7 
     - /path/to/home/.rbenv/shims    <- $PATH starts here
     - ... standard $PATH continues

我怀疑这就是为什么从给定的 Gemfile 安装总是失败的原因。是否有修改 gem 的 shell 路径的正确方法,或者此扩展路径起源于何处?

因此它是引用全局 ruby 的全局捆绑器。你需要做的:

gem install bundler
rbenv rehash

有关正在发生的事情的解释,请参阅 http://dan.carley.co/blog/2012/02/07/rbenv-and-bundler/