不能要求Ruby模块

时间:2012-12-31 13:49:44

标签: ruby

执行文件“dbTest.rb”时:

require 'mysql'
con = Mysql::new("192.168.10.70", "dbuser", "asd1234", "asd")
puts con.get_server_info

通过:

ruby dbTest.rb

我收到错误:

dbTest.rb:1:in `require': no such file to load -- mysql (LoadError)

当我执行“gem list”时,我看到mysql,mysql2和dbd-mysql都在那里。 你能指出我的错误吗?请提前预约。

干杯!

编辑:

由于我不知道的原因,我有两个1.8版本,但宝石正在与正确的红宝石交谈:

cem@skynet:/usr/bin$ sudo update-alternatives --config ruby
[sudo] password for cem: 
There are 2 choices for the alternative ruby (providing /usr/bin/ruby).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/ruby1.8     50        auto mode
  1            /usr/bin/ruby1.8     50        manual mode
  2            /usr/bin/ruby1.9.1   10        manual mode

Press enter to keep the current choice[*], or type selection number: 
cem@skynet:/usr/bin$ sudo update-alternatives --config gem
There are 2 choices for the alternative gem (providing /usr/bin/gem).

  Selection    Path               Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gem1.8     180       auto mode
  1            /usr/bin/gem1.8     180       manual mode
  2            /usr/bin/gem1.9.1   10        manual mode

Press enter to keep the current choice[*], or type selection number:

1 个答案:

答案 0 :(得分:5)

由于您使用的是Ruby 1.8,我相信require 'rubygems'是必需的:

require 'rubygems'
require 'mysql'
con = Mysql::new("192.168.10.70", "dbuser", "asd1234", "asd")
puts con.get_server_info

如果您想了解更多信息,请在“How does require rubygems help find rubygem files?”结帐答案。