如何在每个项目的基础上使用系统Ruby而不是rbenv?

时间:2017-10-16 22:36:58

标签: ruby rubygems rbenv

我正在使用我的工作笔记本电脑为非工作开源项目做出贡献。在工作中我们使用rbenv来管理Ruby版本,但是开源项目似乎希望gem依赖项位于系统Ruby安装文件夹中。因此,当我尝试运行某些项目命令时,我遇到了缺少的gem错误。

该项目是Homebrew,我正在运行的命令是brew style。当我在本地运行命令时,我得到以下内容:

Ignoring rainbow-2.2.2 because its extensions are not built.  Try: gem pristine rainbow --version 2.2.2
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- rainbow (LoadError)
from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/richie.thomas/.gem/ruby/2.3.0/gems/rubocop-0.50.0/lib/rubocop.rb:4:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/richie.thomas/.gem/ruby/2.3.0/gems/rubocop-0.50.0/bin/rubocop:6:in `<top (required)>'
from /Users/richie.thomas/.gem/ruby/2.3.0/bin/rubocop:22:in `load'
from /Users/richie.thomas/.gem/ruby/2.3.0/bin/rubocop:22:in `<main>'

运行gem environment会返回以下内容:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.10
  - RUBY VERSION: 2.3.3 (2016-11-21 patchlevel 222) [x86_64-darwin15]
  - INSTALLATION DIRECTORY: /Users/richie.thomas/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0
  - USER INSTALLATION DIRECTORY: /Users/richie.thomas/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /Users/richie.thomas/.rbenv/versions/2.3.3/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/richie.thomas/.rbenv/versions/2.3.3/bin
  - SPEC CACHE DIRECTORY: /Users/richie.thomas/.gem/specs
....

我被其他贡献者告知,最简单的前进方法是禁用或卸载rbenv以运行命令。我每次想要运行此命令时都非常希望避免卸载并重新安装rbenv,但rbenv documentation中没有提及此内容。

我可以运行任何一次性命令,还是可以更改任何配置设置,以便我可以做我需要做的事情?

1 个答案:

答案 0 :(得分:1)

我重新运行gem environment并注意到定义了以下环境变量:

INSTALLATION DIRECTORY: /Users/richie.thomas/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0
USER INSTALLATION DIRECTORY: /Users/richie.thomas/.gem/ruby/2.3.0

INSTALLATION DIRECTORY的值是我期望用于运行命令的值,我注意到USER INSTALLATION DIRECTORY的值是错误堆栈跟踪中显示的内容。

由于我无法弄清楚我的机器如何确定要使用的变量,我只需将~/.gem/重命名为~/.gem2/并重新运行我最初想要的brew style命令。这很成功!