11

I am having some problems when trying to install gem install mysql2 -v '0.3.17' for Rails. When I try to install it by running gem install mysql2 -v '0.3.17' or gem install mysql2 -v '0.3.17' it gives me the following error:

ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.


Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the file for more
details.  You may need configuration options.

Provided configuration options:
    --with-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
    --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-mysql-config
    --without-mysql-config

Gem files will remain installed in `..../gems/ruby-1.9.3-p392/gems/mysql2-0.3.17 for inspection`.
Results logged to `.../gems/ruby-1.9.3-p392/extensions/x86_64-darwin-14/1.9.1/mysql2-0.3.17/gem_make.out`

How can I fix this and successfully install mysql2?

Thanks all .

Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
Thanh Khiet Nguyen
  • 111
  • 1
  • 1
  • 5
  • Could you include the contents of the `.../gems/ruby-1.9.3-p392/extensions/x86_64-darwin-14/1.9.1/mysql2-0.3.17/gem_make.out` file. It is shown in the last line of the error message as `Results logged to.. ` – Prakash Murthy Jan 08 '15 at 03:03
  • This should help : http://stackoverflow.com/questions/4115126/ruby-gem-mysql2-install-failing – Prakash Murthy Jan 08 '15 at 03:09

4 Answers4

10

I am in Ubuntu 15.04 and I got the same error as stated above.

I did :

 sudo apt-get install libmysqlclient-dev 

After this I did:

gem install mysql2

And now I can successfully do

rails new <app_name> -d mysql

without any errors.

bummi
  • 27,123
  • 14
  • 62
  • 101
Bishisht Bhatta
  • 307
  • 4
  • 16
8

Install libmysqlclient-devel:

CentOS/Fedora:

yum install -y libmysqlclient-devel

Ubuntu:

apt-get install -y libmysqlclient-dev

Mac:

brew install mysql

Hope it helps.

bestmike007
  • 332
  • 1
  • 8
3

hi this might be happening for two reason.

1) You did not install your mysql server for that try

$ brew install mysql

2) didn't specified mysql_config when you are trying to install mysql2 for this try with

$ gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.6.24/bin/mysql_config
Simanto
  • 31
  • 2
2

You need to install MySQL server first. You probably don't have it at the moment.

Lukasz Muzyka
  • 2,783
  • 1
  • 30
  • 41