Installing mysql2 gem on Ruby 1.9.2 and Rails 3.0.8 on Windows

When running ‘bundle install’ or ‘gem install mysql2’, I got following error:

>gem install mysql2
ERROR:  Error installing mysql2:
The ‘mysql2’ native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from ‘http://rubyinstaller.org/downloads’ and follow the instructions
at ‘http://github.com/oneclick/rubyinstaller/wiki/Development-Kit’

To solve this issue and to successfully install mysql2 gem, I took following steps:

1. Download Development Kit “http://github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.1-20101214-1400-sfx.exe” from http://rubyinstaller.org/downloads/
2. Followed the instructions given on linkhttps://github.com/oneclick/rubyinstaller/wiki/Development-Kit
3. Extracted the downloaded DevKit.
4. cd <DEVKIT_INSTALL_DIR>
5. run ruby dk.rb init.

C:\Users\ritesh\Downloads\DevKit-tdm-32-4.5.1-20101214-1400-sfx>ruby dk.rb init
[INFO] found RubyInstaller v1.9.2 at C:/Ruby192
[INFO] found RubyInstaller v1.8.7 at C:/Ruby187
Initialization complete! Please review and modify the auto-generated
‘config.yml’ file to ensure it contains the root directories to all

of the installed Rubies you want enhanced by the DevKit.

6. edit the generated config.yml file as per your system available Rubies version if required
7. [optional] ruby dk.rb review to verify the changes you made to it are correct.

8. finally, ruby dk.rb install to DevKit enhance your installed Rubies.

C:\Users\ritesh\Downloads\DevKit-tdm-32-4.5.1-20101214-1400-sfx>ruby dk.rb install
[INFO] Updating convenience notice gem override for ‘C:/Ruby192’
[INFO] Installing ‘C:/Ruby192/lib/ruby/site_ruby/devkit.rb’
[INFO] Skipping existing gem override for ‘C:/Ruby187’
[WARN] Skipping existing DevKit helper library for ‘C:/Ruby187’

9. You have successfully installed the DevKit, and now comes the step to install mysql2 gem, most important one for which we took so many steps. Make sure you are using Ruby 1.9.2 version.

10. Run gem install myql2 with parameters that I have passed, path can differ for you so make changes accordingly.

>gem install mysql2 — ‘–with-mysql-lib=”c:\Program Files\MySQL\MySQL Server 5.1\lib\opt” –with-mysql-include=”c:\Program Files\MySQL\MySQL Server 5.1\include”‘
Temporarily enhancing PATH to include DevKit…
Building native extensions.  This could take a while…
Successfully installed mysql2-0.2.7
1 gem installed
Installing ri documentation for mysql2-0.2.7…
Enclosing class/module ‘mMysql2’ for class Client not known
Installing RDoc documentation for mysql2-0.2.7…
Enclosing class/module ‘mMysql2’ for class Client not known

And, congrats, you are done with installation of Mysql2 gem on Ruby 1.9.2 and Rails 3.0.8 on Windows.

 

Or…

gem install mysql2 -v 0.2.6
has been working flawlessly for me.

2 Comments

  1. I have this kind of error message if i follow above steps so can u suggest me what to do now?

    Temporarily enhancing PATH to include DevKit…
    Building native extensions. This could take a while…
    ERROR: Error installing mysql2:
    ERROR: Failed to build gem native extension.

    C:/Ruby192/bin/ruby.exe extconf.rb
    checking for rb_thread_blocking_region()… yes
    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.

    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=C:/Ruby192/bin/ruby
    –with-mysql-dir
    –without-mysql-dir
    –with-mysql-include
    –without-mysql-include=${mysql-dir}/include
    –with-mysql-lib
    –without-mysql-lib=${mysql-dir}/lib
    –with-libmysqllib
    –without-libmysqllib

    Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.
    3.6 for inspection.
    Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.3.6/ext/mysql2/ge
    m_make.out
    ERROR: Could not find a valid gem ‘ù’ (>= 0) in any repository
    ERROR: Could not find a valid gem ‘æûwith-mysql-lib=öc:\Program’ (>= 0) in any
    repository
    ERROR: Could not find a valid gem ‘Files\MySQL\MySQL’ (>= 0) in any repository
    ERROR: Possible alternatives: mysql2mysql
    ERROR: Could not find a valid gem ‘Server’ (>= 0) in any repository
    ERROR: Possible alternatives: nserver, tserver, qserver, serve, semver
    ERROR: Could not find a valid gem ‘5.5\lib\optö’ (>= 0) in any repository
    ERROR: Could not find a valid gem ‘ûwith-mysql-include=öc:\Program’ (>= 0) in a
    ny repository
    ERROR: Could not find a valid gem ‘Files\MySQL\MySQL’ (>= 0) in any repository
    ERROR: Possible alternatives: mysql2mysql
    ERROR: Could not find a valid gem ‘Server’ (>= 0) in any repository
    ERROR: Possible alternatives: nserver, tserver, qserver, serve, semver
    ERROR: Could not find a valid gem ‘5.5\includeöæ’ (>= 0) in any repository

Deixe uma resposta

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s