views:

986

answers:

2

Linux 2.6.18-92.el5, ruby 1.8.7, Rails 2.2.2, mysql gem 2.7

I installed the MySQL binary distribution under /usr/local, then installed the mysql gem like this:

gem install mysql --no-rdoc --no-ri \
  -- --with-mysql-include=/usr/local/mysql/include \
  --with-mysql-lib=/usr/local/mysql/lib \
  --with-mysql-config=/usr/local/mysql/bin/mysql_config

When I run irb> require 'mysql' I get the error shown below:

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mysql'
LoadError: libmysqlclient.so.16: cannot open shared object file:
  No such file or directory - 
    /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so
  from /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so
  from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
  custom_require.rb:36:in `require' from (irb):2

After some Googling I found that I could use ldconfig to configure mysql.so to be available to the whole system. Once I added "/usr/local/ mysql/lib" to /etc/ld.so.conf and ran ldconfig, it worked fine:

irb(main):002:0> require 'rubygems'
=> true
irb(main):003:0> require 'mysql'
=> true

OK, so I got it to work. But my question is, why was I getting that error? You used to be able to just gem install mysql and it would work. Has anyone else encountered the same error? Using ldconfig seems kind of brittle and unmaintainable. Is there a better solution?

Any insight would be greatly appreciated.

Thanks,

Ethan

+1  A: 

Possibly it had something to do with the prefix you used when installing mysql? --with-mysql-lib=/usr/local/mysql/lib

Presumably, if that been /usr/local/lib (or somewhere ldconfig was already set to look) and/or if you had just used a top-level prefix of something like /usr/local, you may not have run into problems(?)

pho79
+2  A: 

I had issues as well (on Mac OS X), and was just as frustrated that gem install mysql wasn't as simple as it used to be.

The short-sighted answer is that the mysql gem needs to build native extensions, and to do that, it needs some path information (specific to your system) about MySQL libraries. The most reliable way to get that information is for you to provide it.

The larger answer is that this is a design bug in the gem system. When nearly every other gem installs with gem install foo, the system and the gem submitters need to provide users with some kind of instruction for important exceptional cases - even if it's just feedback with the error message that tells you that you must provide more information to install this gem, and what that information is.

A bit of googling around eventually got me to the answer, but got me a lot more instances of other people blindsided by a simple process that turned complex without warning.

bradheintz