如何要求ruby gem的特定版本?

时间:2021-09-20 07:10:36

Specifically, the ruby-oci8 gem. I have both 1.0.7 and 2.0.4 installed. I want 1.0.7.

具体来说,ruby-oci8宝石。我已经安装了1.0.7和2.0.4。我想要1.0.7。

I can just require oci8, but I don't get the version I want.

我可以只要求oci8,但我没有得到我想要的版本。

irb(main):001:0> require 'oci8'
=> true
irb(main):002:0> OCI8::VERSION
=> "2.0.4"

I can require using the full path to the file, which works, but is not going to be portable:

我可以要求使用文件的完整路径,这是可行的,但不是可移植的:

irb(main):001:0> require 'C:\Ruby\lib\ruby\gems\1.8\gems\ruby-oci8-1.0.7-x86-mswin32-60\lib\oci8'
=> true
irb(main):002:0> OCI8::VERSION
=> "1.0.7"

I can use the gem command to ask for the version I want, but it doesn't appear to actually load the library:

我可以使用gem命令来询问我想要的版本,但它似乎并没有实际加载库:

irb(main):001:0> gem 'ruby-oci8', :lib=>'oci8', :version=>'=1.0.7'
=> true
irb(main):002:0> OCI8::VERSION
NameError: uninitialized constant OCI8
    from (irb):2

I would definitely favor this last approach if would load the library, rather than just confirming that it's present on my system. What am I missing?

如果要加载库,我肯定会支持最后一种方法,而不是仅仅确认它存在于我的系统中。我缺少什么?

2 个解决方案

#1


68  

My problem was twofold:

我的问题是双重的:

1) confusing gem command syntax with that used in config.gem lines in a rails environment.rb configuration file.

1)将gem命令语法与配置中使用的语法混淆。rails环境中的gem行。rb配置文件。

2) failing to issue a require command after the gem command.

2)未在gem命令之后发出require命令。

Proper usage in a script is:

脚本的正确用法是:

gem 'ruby-oci8', '=1.0.7'
require 'oci8'           # example is confusing; file required (oci8.rb) is not 
                         # same name as gem, as is frequently the case

Proper usage in a rails 2.3.x environment.rb file is:

在rails 2.3中正确使用。x环境。rb文件是:

config.gem "ruby-oci8", :version=>'1.0.7'

Thanks to the folks at http://www.ruby-forum.com/topic/109100

感谢http://www.ruby-forum.com/topic/109100的朋友们

#2


1  

Try the following syntax (instead of require):

尝试以下语法(而不是要求):

require_gem 'RMagick' , '=1.10'
require_gem 'RMagick' , '>=1.10'
require_gem 'rake', '>=0.7.0', '<0.9.0'

#1


68  

My problem was twofold:

我的问题是双重的:

1) confusing gem command syntax with that used in config.gem lines in a rails environment.rb configuration file.

1)将gem命令语法与配置中使用的语法混淆。rails环境中的gem行。rb配置文件。

2) failing to issue a require command after the gem command.

2)未在gem命令之后发出require命令。

Proper usage in a script is:

脚本的正确用法是:

gem 'ruby-oci8', '=1.0.7'
require 'oci8'           # example is confusing; file required (oci8.rb) is not 
                         # same name as gem, as is frequently the case

Proper usage in a rails 2.3.x environment.rb file is:

在rails 2.3中正确使用。x环境。rb文件是:

config.gem "ruby-oci8", :version=>'1.0.7'

Thanks to the folks at http://www.ruby-forum.com/topic/109100

感谢http://www.ruby-forum.com/topic/109100的朋友们

#2


1  

Try the following syntax (instead of require):

尝试以下语法(而不是要求):

require_gem 'RMagick' , '=1.10'
require_gem 'RMagick' , '>=1.10'
require_gem 'rake', '>=0.7.0', '<0.9.0'