Pumpkin
Pumpkin

Reputation: 2043

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:

Upvotes: 1

Views: 170

Answers (1)

Eugene Rourke
Eugene Rourke

Reputation: 4944

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?".

Upvotes: 5

Related Questions