我想将所有宝石从一台机器(foo)复制到另一台机器(bar)。这两台机器都是相同的,除了foo安装了一堆宝石而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
我想将所有宝石放在一个共同的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 /
的符号链接对于某些宝石(如rake),一切都按预期工作,对于其他人(如密码盒),它不起作用。对于某些宝石,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命令可以重新生成公共脚本,就像在keybox的情况下显然那样?
答案 0 :(得分:1)
如果您通过端口安装了gem,则以下内容应该可以正常工作
pkg_info | grep rubygem | cut -d ' ' -f 1
pkg_add
安装它们。答案 1 :(得分:1)
尝试使用以下命令:
gem pristine --all
那将从缓存的源(我相信你复制了)重新安装gem,因此应该重新创建脚本包装器,重新编译扩展等等。
您还可以check the documentation调整命令以满足您的需求(如果您想要这样做,只需要恢复可执行文件的标志)。