简体   繁体   中英

Cannot require Ruby module

When executing the file "dbTest.rb" :

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

By :

ruby dbTest.rb

I get the error :

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

When I execute "gem list" , I see mysql, mysql2 and dbd-mysql all there. Can you point out my error ? Thx in advance for your time.

Cheers !

Edit :

For the reasons that are unknown to me I have two 1.8 versions but the gem is talking to the right ruby :

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:

Since you are using Ruby 1.8 I believe require 'rubygems' is required:

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

If you wish to know more, checkout the answer at " How does require rubygems help find rubygem files? ".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM