【发布时间】:2012-03-02 19:54:05
【问题描述】:
我想将我所有的 gem 从一台机器 (foo) 复制到另一台 (bar)。两台机器都是相同的,除了 foo 安装了一堆 gem 而 bar 没有(bar 无法上网)。
我将 /usr/local/lib/ruby/gems 从 foo 复制到 bar,现在 bar 识别出 gem 已安装。
root@bar # gem list
*** LOCAL GEMS ***
keybox (1.2.1)
rake (0.9.2.2)
... and so on
如果我尝试从它们的本地位置运行它们,它们会按预期工作
root@bar # cd /usr/local/lib/ruby/gems/1.8/gems/keybox-1.2.1/bin
root@bar # ./keybox --version
keybox: version 1.2.1
我希望将所有 gem 放在一个公共 bin 目录下,就像它们在 foo 上一样
root@bar # find /usr/local/lib/ruby/gems/1.8/gems/*/bin -type f | xargs -I baz ln -s baz /usr/local/bin/
正如预期的那样,这会创建从每个 gem 的位置到 /usr/local/bin/ 的符号链接
对于某些 gem(如 rake),一切都按预期工作,而对于其他 gem(如 keybox)则不起作用。对于某些 gem,gem 目录中的脚本与安装在 /usr/local/bin 下的脚本之间存在差异。
root@foo # diff /usr/local/lib/ruby/gems/1.8/gems/keybox-1.2.1/bin/keybox /usr/local/bin/keybox
1,4c1,7
< #!/usr/bin/env ruby
< ########################################################################
< #
< ########################################################################
---
> #!/usr/local/bin/ruby18
> #
> # This file was generated by RubyGems.
> #
> # The application 'keybox' is installed as part of a gem, and
> # this file is here to facilitate running it.
> #
6,17c9
< #----------------------------------------------------------------------
< # bootstrap
< #----------------------------------------------------------------------
< begin
< require 'keybox'
< require 'keybox/application/password_safe'
< rescue LoadError
< path = File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
< raise if $:.include? path
< $: << path
< retry
< end
---
> require 'rubygems'
19,21c11
< #----------------------------------------------------------------------
< # instantiate the program and pass it the commandline parameters
< #----------------------------------------------------------------------
---
> version = ">= 0"
23,24c13,16
< keybox = Keybox::Application::PasswordSafe.new(ARGV)
< keybox.run
---
> if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
> version = $1
> ARGV.shift
> end
25a18,19
> gem 'keybox', version
> load Gem.bin_path('keybox', 'keybox', version)
因为我已经将 gem 从一台机器复制到另一台机器,所以我也可以轻松地复制公共脚本,但是有没有更“gemish”的方法呢?是否有一个 gem 命令可以重新生成公共脚本,就像在 keybox 的情况下所做的那样?
【问题讨论】:
-
我可以物理访问“bar”服务器,但它无法访问外部互联网,局域网上也没有 gem 服务器。我想在 bar 上编写一些使用 sequel gem(和其他 gem)的程序。
-
我认为你的 shift 键坏了。你可能想解决这个问题。
-
我在克隆人战争中失去了我的小指。