代码之家  ›  专栏  ›  技术社区  ›  Richie Thomas

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

  •  0
  • Richie Thomas  · 技术社区  · 7 年前

    这个项目是自制的,我运行的命令是 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 documentation 这提到了这一点。

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

    1 回复  |  直到 7 年前
        1
  •  1
  •   Richie Thomas    7 年前

    我重新跑了 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 我最初想要的命令。这是成功的!