本文介绍了将红宝石宝石从一台机器转移到另一台机器的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有的宝石从一台机器(foo)复制到另一台机器(棒)。两台机器都是相同的,只是foo有一堆安装的宝石,而且bar没有(bar不能上网)。



我从foo复制/ usr / local / lib / ruby​​ / gems到bar,现在bar会识别安装的宝石。

  root @ bar#gem list 

***本地GEMS ***

keybox(1.2.1)
rake(0.9.2.2)
...等等

如果我尝试从原生位置运行它们,它们按预期工作

  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 / 

如预期的那样,这会创建符号从每个宝石的位置到/ usr / local / bin / $ /

对于一些宝石(如rake)的链接一切都按预期工作,对于其他人(如keybox),它不起作用。对于一些宝石来说,gem dir中的脚本和/ 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 / ruby​​18
> #
> #这个文件是由RubyGems生成的。
> #
> #应用程序'keybox'作为宝石的一部分安装,
> #这个文件在这里是为了方便运行它。
> #
6,17c9
< #------------------------------------------------- ---------------------
< #bootstrap
< #------------------------------------------------- ---------------------
<开始
<要求'keybox'
<要求'keybox / application / password_safe'
<救援LoadError
< path = File.expand_path(File.join(File.dirname(__ FILE __),..,lib))
<如果包含$ :.路径
< $:<<路径
<重试
<结束
---
>要求'rubygems'
19,21c11
< #------------------------------------------------- ---------------------
< #实例化程序并将命令行参数传递给
< #------------------------------------------------- ---------------------
---
>版本=> = 0
23,24c13,16
< keybox = Keybox :: Application :: PasswordSafe.new(ARGV)
< keybox.run
---
>如果ARGV.first =〜/^_(.*)_$/和Gem :: Version.correct? $ 1然后
>版本= $ 1
> ARGV.shift
>结束
25a18,19
>宝石'钥匙盒',版本
>加载Gem.bin_path('keybox','keybox',版本)

因为我已经复制从一台机器到另一台机器的宝石,我也可以很容易地复制公共脚本,但是有没有更多的宝石方式来做到这一点?是否有一个gem命令会重新生成公开脚本,就像在keybox中显然已经完成的那样?

以下命令:

  gem pristine --all 

这将重新从缓存源(我相信你已经复制)重新安装了gems,因此应该重新创建脚本包装器,重新编译扩展等。



您也可以来调整命令以适合您的需要(有一个标志只是恢复可执行文件,如果这就是你想做的)。


i want to copy all of my gems from one machine (foo) to another (bar). both machines are identical except that foo has a bunch of gems installed and bar does not (bar cannot get onto the internet).

i copied /usr/local/lib/ruby/gems from foo to bar, and now bar recognizes that the gems are installed.

root@bar # gem list

*** LOCAL GEMS ***

keybox (1.2.1)
rake (0.9.2.2)
... and so on

if i try to run them from their native location, they work as expected

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

i would like to have all gems under a common bin dir, like they are on foo

root@bar # find /usr/local/lib/ruby/gems/1.8/gems/*/bin -type f | xargs -I baz ln -s baz /usr/local/bin/ 

as expected, this creates symbolic links from each gem's location to /usr/local/bin/

for some gems (like rake) everything works as expected, for others (like keybox) it does not work. for some gems, there's a difference between the script in the gem dir and the one that gets installed under /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)

since i'm already copying gems from one machine to another i could just as easily copy the public scripts as well, but is there a more "gemish" way to do it? is there a gem command that will regenerate the public scripts as has apparently been done in the case of keybox?

解决方案

Try using the following command:

gem pristine --all

That will reinstall the gems from the cached source (which I believe you copied), and therefore should recreate script wrappers, recompile extensions, etc.

You can also check the documentation to adjust the command to suit your needs (there's a flag to just restore the executables, if that's all you want to do).

这篇关于将红宝石宝石从一台机器转移到另一台机器的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 20:31