我遇到了RVM问题。一般来说,我使用项目特定的宝石集;然而,最近当我在@global gemset中安装gem时,当我在特定项目中工作时它不可用。这是我尝试安装 hpricot gem的示例。这是在安装宝石并开始新壳之后。
$ 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中再次安装它。
谢谢..
答案 0 :(得分:2)
这里的问题是我第一次安装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)
根据需要,宝石可供项目使用。
答案 1 :(得分:0)
我遇到了同样的事情并做了一些实验
$ 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中,您应该能够在项目的上下文中使用它。