Rbenv 错误 gem 安装路径 - 找不到 gem

Rbenv wrong gem installation path - can't find gem

我遇到了 rbenv 的问题,我认为问题是 require 试图从我的系统 gems 而不是垫片中读取。

我正在尝试创建一个脚本文件而不需要捆绑包的开销 - 虽然我已经尝试添加一个 Gem 文件并将脚本和 Gem 文件放在同一目录中.

可重现的步骤:

  1. brew install rbenv
  2. export PATH="$HOME/.rbenv/bin:$PATH" 在我的 .zshrc
  3. eval "$(rbenv init -)" 添加到我的 .zshrc
  4. 来源:. ~/.zshrc
  5. rbenv install 2.6.3
  6. rbenv rehash
  7. rbenv global 2.6.3
  8. rbenv rehash 为简洁起见
  9. 关闭终端
  10. 新终端:
    • ruby -v = "ruby 2.6.3p62"
    • rbenv version = "2.6.3 (由$HOME/Desktop/.ruby-版本设置)"
  11. which ruby = "$HOME/.rbenv/shims/ruby"
  12. gem env
    • 安装目录:$HOME/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0
    • 用户安装目录:$HOME/.gem/ruby/2.6.0
    • RUBY 可执行:$HOME/.rbenv/versions/2.6.3/bin/ruby
    • 可执行目录:$HOME/.rbenv/versions/2.6.3/bin
    • SPEC 缓存目录:$HOME/.gem/specs
    • 系统配置目录:$HOME/.rbenv/versions/2.6.3/etc
    • RUBYGEMS 平台:
      • ruby
      • x86_64-darwin-18
    • GEM 路径:
      • $HOME/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0
      • $HOME/.gem/ruby/2.6.0
  13. gem install colorize - 这个 gem 似乎工作正常
  14. gem install httparty
  15. gem install pry
  16. 文件头:

    #!/usr/bin/ruby
    
    require 'httparty'
    require 'colorize'
    require 'pry'
    
  17. ./file.rb
  18. HTTParty 的堆栈跟踪
    /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/dependency.rb:319:in 'to_specs': Could not find 'multi_xml' (>= 0.5.2) among 17 total gem(s) (Gem::LoadError)
    Checked in 'GEM_PATH=$HOME/.gem/ruby/2.3.0:/Library/Ruby/Gems/2.3.0:/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0', execute `gem env` for more information
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:1442:in `block in activate_dependencies'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:1431:in `each'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:1431:in `activate_dependencies'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/specification.rb:1413:in `activate'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:196:in `rescue in try_activate'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:193:in `try_activate'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:125:in `rescue in require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:39:in `require'
    from ./cdw-demo.rb:3:in `<main>'
    
  19. Pry 的堆栈跟踪
    /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- pry (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from ./cdw-demo.rb:4:in `<main>'
    

堆栈跟踪显示 multi_xml 可能存在问题,因为缺少 gem,但它是通过 httparty

安装的

Gem 列表: gem list

*** LOCAL GEMS ***

bigdecimal (default: 1.4.1)
bundler (2.1.4, default: 1.17.2)
cmath (default: 1.0.0)
coderay (1.1.2)
colorize (0.8.1)
csv (default: 3.0.9)
date (default: 2.0.0)
dbm (default: 1.0.0)
did_you_mean (1.3.0)
e2mmap (default: 0.1.0)
etc (default: 1.0.1)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.1.0)
forwardable (default: 1.2.0)
gdbm (default: 2.0.0)
httparty (0.17.3)
io-console (default: 0.4.7)
ipaddr (default: 1.2.2)
irb (default: 1.0.0)
json (default: 2.1.0)
logger (default: 1.3.0)
matrix (default: 0.1.0)
method_source (0.9.2)
mime-types (3.3.1)
mime-types-data (3.2019.1009)
minitest (5.11.3)
multi_xml (0.6.0)
mutex_m (default: 0.1.0)
net-telnet (0.2.0)
openssl (default: 2.1.2)
ostruct (default: 0.1.0)
power_assert (1.1.3)
prime (default: 0.1.0)
pry (0.12.2)
psych (default: 3.1.0)
rake (12.3.2)
rdoc (default: 6.1.0)
rexml (default: 3.1.9)
rss (default: 0.2.7)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
shell (default: 0.7)
stringio (default: 0.0.2)
strscan (default: 1.0.0)
sync (default: 0.5.0)
test-unit (3.2.9)
thwait (default: 0.1.0)
tracer (default: 0.1.0)
webrick (default: 1.4.2)
xmlrpc (0.3.0)
zlib (default: 1.0.0)

如果需要更多信息,请告诉我。

与其使用 /usr/bin/ruby 安装的系统 Ruby,不如使用 hashbang

#!/usr/bin/env ruby

这应该指向您支持的全局 rbenv Ruby。