2011-05-10 52 views
3

我遇到了RVM问题。一般来说,我使用项目特定的宝石;然而,最近当我在@global gemset中安装一个gem时,当我在一个特定的项目中工作时它不可用。这里是一个例子,我试图安装宝石hpricot。安装完宝石并启动一个新壳之后,这是正确的。RVM - 无法使用@global gemset中的宝石

$ 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 [email protected] 
Using /home/bshaver/.rvm/gems/ruby-1.9.2-p180 with gemset myproject-gems 

$ gem list | grep hpricot 

$ rvm info 

[email protected]: 

    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 ([email protected]) [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/[email protected]" 
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/[email protected]/bin/rake" 

    environment: 
PATH:   "/home/bshaver/.rvm/gems/[email protected]/bin:/home/bshaver/.rvm/gems/[email protected]/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/[email protected]" 

GEM_PATH:  "/home/bshaver/.rvm/gems/[email protected]:/home/bshaver/.rvm/gems/[email protected]" 
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中。

谢谢..

回答

2

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

解释器的默认gemset和该解释器的gemset之间是有区别的。

所以,你可以通过

$ rvm use [email protected] 
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 [email protected] 
Using /home/bshaver/.rvm/gems/ruby-1.9.2-p180 with gemset myproject-gems 

$ gem list | grep validation_reflection 
validation_reflection (1.0.0) 

达到预期的效果和创业板可以以项目为所需。

0

我遇到了同样的事情,做了一些尝试

$ gem list 

... 
tzinfo (0.3.29, 0.3.28) 
uglifier (1.0.0) 
wirble (0.1.3) 

然后在调试器控制台(需要宝石ruby-debug对Ruby 1.8.7或ruby-debug19为Ruby 1.9.2) :在gem list上市

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 

一切都从Gemfile中或它的一个依赖的瑰宝。我相信Rails在启动应用程序之前调用Bundler创建gem上下文。我需要更多的阅读来确定这一点,但这似乎是这样的。

因此,对于您的情况,请将gem 'hpricot'添加到您的gem文件中,并且您应该可以在项目上下文中使用它。

+0

感谢Eric的回应。如果我正确理解你的话,那么它不适合我。当我将'hpricot'添加到Gemfile中时,它应该通过'bundle check',但它返回**您的Gemfile的依赖不能满足**即使缺少的gem在GEM_PATH中安装_somewhere_。 – shakerlxxv 2011-07-12 21:58:04

+0

将这个添加到您的gemfile后,您仍然必须运行'bundle install'。我相信bundler会为每个项目创建一个单独的上下文,并且只会检查这些文件夹。只有将gem install '安装在gemfile中并运行'bundle install'后才可用。 – 2011-07-12 22:15:10

+0

啊,但运行'bundle install'会将缺少的宝石的第二个实例安装到项目特定的gemset中。根据RVM参考资料,[@global](https://rvm.beginrescueend.com/gemsets/global/)应允许在项目之间共享gem的单个副本。然而,当我正在寻找安装我的宝石的2个目录时,答案就出现了,因为第一个安装目录不在** @ global ** gemset下。 – shakerlxxv 2011-07-13 01:48:59