Focus on IT Recommend

Home > Issues with Rails gem mysql2 on OS X 10.7 with Ruby 1.9.2 and Rails 3.1

Issues with Rails gem mysql2 on OS X 10.7 with Ruby 1.9.2 and Rails 3.1



OS Version: Mac OS X 10.7.1 Lion
Ruby Version: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
Ruby Location: /usr/local/rvm/bin/ruby
Rails Version: Rails 3.1.0
Rails Location: /usr/local/rvm/gems/ruby-1.9.2-p290/bin/rails

Now, I installed the mysql2 gem and when I run gem list it shows up in the list as: mysql2 (0.3.7)

So far so good, right? OK, so here's where it gets tricky. No matter what I do, I can't start the server. In terminal I cd to the directory my rails app is and run rails s. However, instead of starting i get this:

/usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2.rb:9:in `require': dlopen(/usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle
  Reason: image not found - /usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.7/lib/mysql2.rb:9:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `each'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:66:in `block in require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `each'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler/runtime.rb:55:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.18/lib/bundler.rb:120:in `require'
    from /Users/doug/Sites/simple_cms/config/application.rb:7:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:52:in `require'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:52:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:49:in `tap'
    from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/commands.rb:49:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Obviously, this is not what should be happening. The problem is I can't figure out why not. None of the solutions I've come across have worked.

This is actually my first attempt at getting Ruby/RoR working on my computer. I'm following a tutorial from and, unsurprisingly, this doesn't happen to the guy doing the videos.

I've tried searching and, as I said, nothing seems to help. Ideas?

Recommend:ruby on rails - mysql2 gem installation on linux

e installing mysql2 (0.3.11), and Bundler cannot continue.Make sure that gem install mysql2 -v '0.3.11' succeeds before bundling. What do I need to do now ruby-on-rails
  this question edited Aug 10 '12 at 10:35 Frederick C

ruby-on-rails ruby gem osx-lion mysql2
asked Sep 27 '11 at 2:40 dougoftheabaci 112 1 10      How you install mysql and have you started mysql-server? –  venj Sep 27 '11 at 2:58      Check the following link for a resolution to this problem:… –  Si1entSpike Sep 27 '11 at 3:08      Steve pointed me to another question with an answer I'd missed. The solution was as follows: sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib My guess is that since I installed it multi-user rather than single-user the other solutions weren't lining up correctly. This, however, does. –  dougoftheabaci Sep 27 '11 at 7:42


1 Answers

install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p290@[gemset name]/gems/mysql2-0.3.7/lib/mysql2/mysql2.bundle

[gemset name] = the name of the gemset you are using -- if you didn't set one then you should set it as that is one of the main points of getting rvm

hope that helps

answered Sep 27 '11 at 3:51 noob 931 2 12 32


Recommend:mysql - gem mysql2 not installed on ruby on rails

lling mysql2: Failed to build gem native extension 23 answers I have installed following versions: ruby 1.9.3p484 (2013-11-22) [i386-mingw32] rails 4.0.2 DevKit-tdm-32-4.5.2-20111229-1559-sfx rubygems-2.1.11 MySQL Server 5.6 mysql-connector


------splitte line----------------------------