3

I'm trying to access my first ruby project. After navigating to the proper directory and typing:

$ rails server

I get the following error message:

/Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb:7:in require': dlopen(/Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
Referenced from: /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb:7:in
'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in require'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in
block (2 levels) in require'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in each'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in
block in require'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in each'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in
require'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.10/lib/bundler.rb:120:in require' from /Users/Rozey/Sites/first_project/config/application.rb:7:in'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/commands.rb:28:in require'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/commands.rb:28:in
block in '
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/commands.rb:27:in tap'
from /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.5/lib/rails/commands.rb:27:in
'
from script/rails:6:in require'
from script/rails:6:in
'

I had previously installed the mysql2 gem using RVM. I know there is probably a simple fix but I'm new to this, so I appreciate your help.

Some extra information:

Rozey$ which ruby
/Users/Rozey/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Rozey$ which mysql
/usr/local/mysql/bin/mysql

s2t2
  • 2,462
  • 5
  • 37
  • 47
  • How have you installed MySQL, from source or brew or ...? – svoop Mar 22 '11 at 16:59
  • From http://www.mysql.com/downloads/mysql/ using the 64-bit DMG option. I also used RVM to install the mysql gem. – s2t2 Mar 22 '11 at 20:24
  • Alright, I don't have a fix for your specific problem at hand then, but the solution is most likely the `install_name_tool` utility which fixed similar issues I've had with Gentoo Prefix in the past. – svoop Mar 23 '11 at 11:26
  • thanks @lebreeze and @svoop for the suggestions. I tried the following but an still getting the same error sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.18.dylib /usr/local/mysql/lib/mysql/libmysqlclient.18.dylib /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/mysql2/mysql2.bundle – s2t2 Mar 23 '11 at 15:23
  • possible duplicate of [Library not loaded: libmysqlclient.16.dylib error when trying to run 'rails server' on OS X 10.6 with mysql2 gem](http://stackoverflow.com/questions/4546698/library-not-loaded-libmysqlclient-16-dylib-error-when-trying-to-run-rails-serv) – the Tin Man Dec 25 '11 at 00:45

3 Answers3

3

Have you had a look at How to fix "dlopen(/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib"?

It looks like it could be a similar issue

Community
  • 1
  • 1
lebreeze
  • 5,094
  • 26
  • 34
  • 2
    Thanks @lebreeze and @svoop for suggesting the correct technique. I was having troubles entering the correct paths so I went into the chat room at http://webchat.freenode.net/?channels=rvm where @esparkman proposed the following solution. It worked! >sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib /Users/Rozey/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle then >sudo ln /usr/local/mysql-5.5.10-osx10.6-x86_64/bin/mysql /usr/local/mysql/bin/mysql – s2t2 Mar 23 '11 at 21:04
3
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/" 

Dropped that in bash.profile and worked like a charm

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
1

I tried all of the above and none of it worked. I found this on another page Library not loaded: libmysqlclient.16.dylib error when trying to run 'rails server' on OS X 10.6 with mysql2 gem and it worked like a charm:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Community
  • 1
  • 1