Trouble Installing mysql2 Gem on Windows 8 with Ruby2

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 from C:/mysql/lib to your Ruby bin folder
  • Optional: delete C:/mysql


This post currently has 7 responses

  1. David says:

    Just what happened to me tonight… Thanks for the solution. Guess latest tech has its drawbacks…

    • says:

      Yeah, this had me banging my head against the desk for a good while. Glad you got it figured out!

  2. John says:

    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 !!

  3. amemrohd says:

    Thanks a lot.Been working on it for 4 hrs

  4. Roberto Júnior says:

    Thanks a lot man, this really helps!!!

  5. Bhargav Mehta says:

    Thanks alot man, this was awesome !!!!

  6. mbonell says:

    Thanks 😀

Comments are closed!