【问题标题】:RVM - Not able to use gems from the @global gemsetRVM - 无法使用来自 @global gemset 的 gem
【发布时间】:2011-05-10 15:31:55
【问题描述】:

我遇到了关于 RVM 的问题。一般来说,我使用项目特定的 gemsets;但是,最近当我将 gem 安装到 @global gemset 中时,当我在特定项目中工作时它不可用。这是我尝试安装 hpricot gem 的示例。这是在安装 gem 并启动新的 shell 之后。

$ rvm use ruby-1.9.2
Using /home/bshaver/.rvm/gems/ruby-1.9.2-p180

$ gem list

*** LOCAL GEMS ***

bundler (1.0.12)
hpricot (0.8.4)
rake (0.8.7)

$ rvm use ruby-1.9.2@myproject-gems
Using /home/bshaver/.rvm/gems/ruby-1.9.2-p180 with gemset myproject-gems

$ gem list | grep hpricot

$ rvm info

ruby-1.9.2-p180@myproject-gems:

  system:
uname:       "Linux hawkeye.localdomain 2.6.35.12-88.fc14.x86_64 #1 SMP Thu Mar 31 21:21:57 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux"
bash:        "/bin/bash => GNU bash, version 4.1.7(1)-release (x86_64-redhat-linux-gnu)"
zsh:         " => not installed"

  rvm:
version:      "rvm 1.5.2 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]"

  ruby:
interpreter:  "ruby"
version:      "1.9.2p180"
date:         "2011-02-18"
platform:     "x86_64-linux"
patchlevel:   "2011-02-18 revision 30909"
full_version: "ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]"

  homes:
gem:          "/home/bshaver/.rvm/gems/ruby-1.9.2-p180@myproject-gems"
ruby:         "/home/bshaver/.rvm/rubies/ruby-1.9.2-p180"

  binaries:
ruby:         "/home/bshaver/.rvm/rubies/ruby-1.9.2-p180/bin/ruby"
irb:          "/home/bshaver/.rvm/rubies/ruby-1.9.2-p180/bin/irb"
gem:          "/home/bshaver/.rvm/rubies/ruby-1.9.2-p180/bin/gem"
rake:         "/home/bshaver/.rvm/gems/ruby-1.9.2-p180@global/bin/rake"

  environment:
PATH:         "/home/bshaver/.rvm/gems/ruby-1.9.2-p180@myproject-gems/bin:/home/bshaver/.rvm/gems/ruby-1.9.2-p180@global/bin:/home/bshaver/.rvm/rubies/ruby-1.9.2-p180/bin:/home/bshaver/.rvm/bin:/usr/local/java/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/real/RealPlayer/:/home/bshaver/bin:/home/bshaver/test-root/bin:/home/bshaver/Documents/scripts/"
GEM_HOME:     "/home/bshaver/.rvm/gems/ruby-1.9.2-p180@myproject-gems"

GEM_PATH:     "/home/bshaver/.rvm/gems/ruby-1.9.2-p180@myproject-gems:/home/bshaver/.rvm/gems/ruby-1.9.2-p180@global"
MY_RUBY_HOME: "/home/bshaver/.rvm/rubies/ruby-1.9.2-p180"
IRBRC:        "/home/bshaver/.rvm/rubies/ruby-1.9.2-p180/.irbrc"
RUBYOPT:      ""
gemset:       "myproject-gems"

知道为什么 hpricot 在项目 gemset 中不可用吗? bundler 我也遇到了同样的问题,但最终在 gemset 中再次安装了它。

谢谢..

【问题讨论】:

    标签: rubygems rvm


    【解决方案1】:

    这里的问题是我第一次安装 hpricot gem 时没有使用 @global gemset。

    解释器的默认 gemset 与该解释器的 @global gemset 之间存在差异。

    所以你可以通过

    达到想要的结果
    $ rvm use ruby-1.9.2@global
    Using /home/bshaver/.rvm/gems/ruby-1.9.2-p180 with gemset global
    
    $ gem install validation_refelection
    Fetching: validation_reflection-1.0.0.gem (100%)
    Successfully installed validation_reflection-1.0.0
    1 gem installed
    Installing ri documentation for validation_reflection-1.0.0...
    Installing RDoc documentation for validation_reflection-1.0.0...
    
    $ rvm use ruby-1.9.2@myproject-gems
    Using /home/bshaver/.rvm/gems/ruby-1.9.2-p180 with gemset myproject-gems
    
    $ gem list | grep validation_reflection
    validation_reflection (1.0.0)
    

    并且 gem 可以根据需要用于项目。

    【讨论】:

      【解决方案2】:

      我遇到了同样的事情并做了一些实验

      $ gem list
      
      ...
      tzinfo (0.3.29, 0.3.28)
      uglifier (1.0.0)
      wirble (0.1.3)
      

      然后在调试器控制台中(对于 ruby​​ 1.8.7 需要 gem ruby-debug 或对于 ruby​​ 1.9.2 需要 ruby-debug19):

      ruby-1.9.2-p180 :001 > puts `gem list`  #note that those are not quotes, but backticks
      
      ...
      tzinfo (0.3.28)
      wirble (0.1.3)
       => nil 
      

      gem list 中列出的所有内容都是 gemfile 或其依赖项之一中的 gem。我相信 Rails 在启动应用程序之前会调用 Bundler 来创建 gem 上下文。我需要更多阅读才能确定这一点,但情况似乎就是这样。

      因此,根据您的情况,将gem 'hpricot' 添加到您的gemfile 中,您应该能够在项目的上下文中使用它。

      【讨论】:

      • 感谢 Eric 的回复。如果我正确理解你的说法,它对我不起作用。当我将“hpricot”添加到 Gemfile 时,它​​应该通过 bundle check,但它返回 您的 Gemfile 的依赖项无法满足,即使缺少的 gem 安装在 某处 在 GEM_PATH 中。
      • 在将其添加到 gemfile 之后,您仍然需要运行 bundle install。我相信 bundler 会为每个项目创建一个单独的上下文,并且只会检查这些文件夹。使用 gem install <gemname> 安装的 Gem 在您将它们放入 gemfile 并运行 bundle install 之前不可用。
      • 啊,但是运行 bundle install 会将缺少的 gem 的第二个实例安装到项目特定的 gemset 中。根据 RVM 参考,@global 应该允许 gem 的单个副本在项目之间共享。但是,当我在寻找安装我的 gem 的 2 个目录时,答案就出现了,因为第一个安装目录不在 @global gemset 下。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多