RVM/rbenv RVM 的 default gemset 和 global gemset 有什么区别?

pinepara · 2013年07月28日 · 最后由 deveyy 回复于 2013年12月09日 · 10141 次阅读

如题,RVM 的文档是这么说的

NOTE: A little bit about where the default and global gemsets differ. If you don't use a gemset at all, you get the gems in the 'default' set. If you use a specific gemset (say @testing), it will inherit gems from that ruby's @global. The 'global' gemset is to allow you to share gems to all your gemsets. The word 'default' quite literally says it all, eg. the gemset used without selecting one for a specific installed ruby.

说实话没太看懂,实际使用上有区别么?

global 是所有 gemset 共享的。default 是在没有显示指定 gemset 的时候用的 gemset。比如你在 global gemset 里装了个 bundler 那么所有新建的 gemset 里就都包含这个 gmeset

#1 楼 @doitian 可是在使用其他 gemset 时也可以使 default gemset 中的 gems 啊,那么 global gemset 有什么必要呢?

#2 楼 @pinepara 我记得,在其他 gemset 中,不能使用 default gemset 中的 gems

#3 楼 @ery 试了一下,确实是这样的。不过有一个新的问题,那 Ruby 2.0 的那些 default gems 是怎么做到跨 gemset 的呢?我把 global gemset 删掉依然在其他 gemset 中依然可以使用。

rvm info | grep GEM_PATH

#4 楼 @pinepara 在试试 rvm info | grep global

#6 楼 @ery

╭─ junzhou@x200 ~ (ruby-2.0.0-p247@global)
╰─ rvm info | grep GEM_PATH                              
    GEM_PATH:     "/home/junzhou/.rvm/gems/ruby-2.0.0-p247@global"
╭─ junzhou@x200 ~ (ruby-2.0.0-p247@global)
╰─ ls /home/junzhou/.rvm/gems/ruby-2.0.0-p247@global/gems
rvm-1.11.3.8
╭─ junzhou@x200 ~ (ruby-2.0.0-p247@global)
╰─ gem list                                               

*** LOCAL GEMS ***

bigdecimal (1.2.0)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
rvm (1.11.3.8)
test-unit (2.0.0.0)

似乎 Ruby default gems 不在 GEM_PATH 里面?

#6 楼 @ery 切换到 default gemset 下:

╭─ junzhou@x200 ~ (ruby-2.0.0-p247)
╰─ rvm info | grep GEM_PATH                                        
    GEM_PATH:     "/home/junzhou/.rvm/gems/ruby-2.0.0-p247:/home/junzhou/.rvm/gems/ruby-2.0.0-p247@global"
╭─ junzhou@x200 ~ (ruby-2.0.0-p247)
╰─ ls /home/junzhou/.rvm/gems/ruby-2.0.0-p247/gems
rake-0.9.6  rdoc-4.0.0  test-unit-2.0.0.0

很奇怪还是有一些 gems 找不到

#8 楼 @pinepara 试试 gem which bigdecimal

#9 楼 @ery 谢谢!gem which 命令很有用

╭─ junzhou@x200 ~ (ruby-2.0.0-p247)
╰─ gem which bigdecimal
/home/junzhou/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/bigdecimal.so
╭─ junzhou@x200 ~ (ruby-2.0.0-p247)
╰─ gem which json      
/home/junzhou/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/json.rb

不过 io-console 比较奇怪,gem which 命令没找到

╭─ junzhou@x200 ~ (ruby-2.0.0-p247)
╰─ gem which io-console                                        
ERROR:  Can't find ruby library file or shared library io-console

猜测可能在这

╭─ junzhou@x200 ~ (ruby-2.0.0-p247)
╰─ ls /home/junzhou/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/io/console.so 
/home/junzhou/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/io/console.so

现在回收行业出现了 R V M 这方面的信息,可以看看 http://www.incomrecycle.com方面的知识

需要 登录 后方可回复, 如果你还没有账号请 注册新账号