Rails gem install mysql throws error: *** extconf.rb failed ***

Whilst reading guides on how to setup a rails dev server under OS X (both Tiger and Leopard), I kept running into issues installing the mysql gem. The guides would instruct you to install the mysql client libraries from the mysql website, which is fine. But to get improved performance under rails, you must install the mysql gem, but in doing so, I would constantly run into issues getting the gem to install correctly. The issues normally arises after running the following command:

sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

And the resulting error is:

checking for mysql_query() in -lmysqlclient... no

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of

necessary libraries and/or headers.  Check the mkmf.log file for more

details.  You may need configuration options.

Basically, the gem compile fails as a result of not knowing where the correct mysql files are, despite the fact that the command line switch points to the mysql folder.

To fix this problem, use a line like the following:

sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Note that instead of pointing at the mysql folder, we are pointing at a mysql config which is bundled with the mysql client install files.

Tags: , , , , ,

48 comments

  1. Had the same problem, and fixed it per your post. Thanks!

    ReplyReply
  2. I also had the same issue and your instructions fixed them. Thanks a ton

    ReplyReply
  3. thanks !

    ReplyReply
  4. Another big thanks! Just what I needed.

    ReplyReply
  5. Helped here too. Many thanks.

    ReplyReply
  6. THX you guy! It helps!!

    ReplyReply
  7. THX! Worked for me too!

    ReplyReply
  8. Same problem, same solution. Thanks for the help!

    ReplyReply
  9. Great, thanks, worked for me too.

    ReplyReply
  10. Dude you rock. Thanks

    ReplyReply
  11. Wow, thanks. That really helped!

    ReplyReply
  12. worked like a gem. thanks!

    ReplyReply
  13. this is AWESOME. thanks.

    ReplyReply
  14. I love you, and would like to have your babies. This has been flummoxing me for ages.

    ReplyReply
  15. Thanks a lot.

    ReplyReply
  16. Sweet! I can’t understand how will people know these tricks.. and when will be able to give such advice..

    ReplyReply
  17. You rock. Thank you!!!

    ReplyReply
  18. Awesome! It took three hours to figure this thing out.

    ReplyReply
  19. Thank you!

    ReplyReply
  20. Gracias!

    I guess that a bug report needs to be submitted somewhere.

    ReplyReply
  21. Good stuff, thanks!

    ReplyReply
  22. If using jruby, above commond will still through an error. You will need to architecture flag. Here is the command for jruby

    sudo env ARCHFLAGS=”-arch i386″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config
    # This sets the ARCHFLAGS environment variable to your native architecture

    ReplyReply
  23. THANK YOU!!!!

    ReplyReply
  24. U DA MAN

    ReplyReply
  25. I’ve got wsod when I’m adding comment here;/

    ReplyReply
  26. I’ve got similar problem, but this solution wasn’t helpful for me.
    In my case I haven’t gcc installed;/

    Read more: http://easyanswers.org/question/extconfrb-failed-gem-install-mysql

    ReplyReply
  27. Worked, Thanks!

    ReplyReply
  28. Brilliant! thanks

    ReplyReply
  29. I spend lots of time searching to make it work.
    you have the solution,it finally work.
    thanks very much

    ReplyReply
  30. Just a quick note, I was using MacPorts to install and was running into the same errors. The fix was to point the installer to where MacPorts installed mysql_config… like this:

    sudo gem install mysql — –with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

    ReplyReply
  31. Thanks! I’ve spent a lot of time searching for a solution, and this did it for me!

    ReplyReply
  32. Worked a treat! Thanks a lot! :)

    ReplyReply
  33. Matthew Kosterman

    Woohoo! Thank you.

    ReplyReply
  34. Like the others before. Thank you soooo much. Saved my ass. =)

    ReplyReply
  35. Got it working for me as well. Many thanks

    ReplyReply
  36. exactly! thank you 1000*times :-)

    ReplyReply
  37. it didnt help me
    i am using snow leopard
    my error is of following type

    $ sudo gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config
    Building native extensions. This could take a while…
    ERROR: Error installing mysql:
    ERROR: Failed to build gem native extension.

    /opt/local/bin/ruby extconf.rb –with-mysql-config=/usr/local/mysql/bin/mysql_config
    checking for mysql_ssl_set()… no
    checking for rb_str_set_len()… no
    checking for rb_thread_start_timer()… no
    checking for mysql.h… no
    checking for mysql/mysql.h… no
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers. Check the mkmf.log file for more
    details. You may need configuration options.

    Provided configuration options:
    –with-opt-dir
    –without-opt-dir
    –with-opt-include
    –without-opt-include=${opt-dir}/include
    –with-opt-lib
    –without-opt-lib=${opt-dir}/lib
    –with-make-prog
    –without-make-prog
    –srcdir=.
    –curdir
    –ruby=/opt/local/bin/ruby
    –with-mysql-config

    Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
    Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

    please help me out of here..
    thanks

    ReplyReply
  38. A big THANK YOU!

    ReplyReply
  39. @gagan shrestha: I’m not familiar with the setup of Rails & Ruby on Snow Leopard – Sorry!

    ReplyReply
  40. Worked like a charm, thanks ..

    ReplyReply

Leave a comment

Additional comments powered by BackType