I recently installed the 64 bit version of Ruby 2.0 on my Windows 8 machine.
All of my old projects I tested with it ran just fine and the world was a happy place.
Then I had to install Rails, so that I could make some minor changes to an existing app… and the pain began.
The problem
Cutting a long story short, I couldn’t for the life of me get the mysql2 gem to compile and install.
This is the error message I got:
C:/Ruby200-x64/bin/ruby.exe extconf.rb
checking for main() in -llibmysql... 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.
I followed numerous instructions from across the internet (example) as to how this might be achieved.
Most seemed to indicate that you could set the --with-mysql-dir
flag accordingly and although this got me close, no dice.
The solution
This is what worked for me. Hopefully it’ll help someone else.
- Uninstall the 64 bit version of Ruby 2 (apparently, there are lot of libraries that haven’t been tested against 64 bit Ruby on Windows and it can lead to errors)
- Download the latest 32 bit Ruby 2 version from here and install
- Download the 32 bit version of the DevKit from the same link as above and follow these instructions to have it enhance your previously installed Ruby version
- Download the 32 bit MySQL C connector (archive version) from here and unzip it to C:/mysql
- Open a command prompt and enter
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/mysql"
- Copy the file
libmysql.dll
fromC:/mysql/lib
to your Rubybin
folder - Optional: delete
C:/mysql
Reference: https://github.com/oneclick/rubyinstaller/issues/191
Just what happened to me tonight… Thanks for the solution. Guess latest tech has its drawbacks…
Yeah, this had me banging my head against the desk for a good while. Glad you got it figured out!
Thanks a million … to say I was trying to mysql2 installed for 6 hours is not an exaggeration …. but with your explanation all up and running, thankfully !!
Thanks a lot.Been working on it for 4 hrs
Thanks a lot man, this really helps!!!
Thanks alot man, this was awesome !!!!
Thanks