Railsで「mysql2」を利用する際、bundle installをするとタイトルのようなエラーが出力された。
かなりの時間これに悩まされた。具体的には以下のようなエラー。
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/★★★/.rvm/rubies/ruby-1.9.3-p385/bin/ruby extconf.rb --with-mysql-config=/usr/local/Cellar/mysql/5.5.20/bin/mysql_config checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes *** 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 --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=/Users/sanpeihiroki/.rvm/rubies/ruby-1.9.3-p385/bin/ruby --with-mysql-config extconf.rb:33:in ``': No such file or directory - /usr/local/Cellar/mysql/5.5.20/bin/mysql_config --cflags (Errno::ENOENT) from extconf.rb:33:in `<main>' Gem files will remain installed in /Users/★★★/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.11 for inspection. Results logged to /Users/★★★/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.11/ext/mysql2/gem_make.out An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
下記に解決方法を示すが、果たしてこれにより解決したかどうかは定かではない。
あくまで参考程度のメモである。
まず、mysqlを64bit版に変更する。
既存のmysqlが32bit版の可能性がある場合、64bit版に変更する。
アンインストール方法はここのサイトの通りにやると上手くいった。
インストールは公式サイトから行う。
64bit版のdmgを選択すること。
また、ダウンロードのリンクが探しにくいので注意。ログインはする必要なし。
※以下の画像を参照
ダウンロードが終わったら、インストールをする。2つのpkgファイルをまずインストールし、その後
MySQL.prefpaneをインストールした。
ここまでを行った後、再度bundle installをしたが、まだ上述のエラがーはかれる。
ここで、「sudo gem install mysql2」を実行する
% sudo gem install mysql2 Building native extensions. This could take a while... Successfully installed mysql2-0.3.11 1 gem installed Installing ri documentation for mysql2-0.3.11... Installing RDoc documentation for mysql2-0.3.11...
すると、インストールに成功した。
再度bundle installを行うと上手くいった。
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.