Ruby on Railsをちょっと触ってみたときにmysql2で引っかかったときのメモです
環境はBash on Windowsです。
スポンサーリンク
そもそもmysql2が入っていなかった
実行すると、
You have requested: mysql2 < 0.5, >= 0.3.18 The bundle currently has mysql2 locked at 0.4.10. Try running `bundle update mysql2` If you are updating multiple gems in your Gemfile at once, try passing them all to `bundle update` Run `bundle install` to install missing gems.
とのエラーメッセージが出ました。
なのでbundle update mysql2をしてみると、
--- ERROR REPORT TEMPLATE ------------------------------------------------------- # Error Report ## Questions Please fill out answers to these questions, it'll help us figure out why things are going wrong. - **What did you do?** I ran the command `/home/kagerou/.rbenv/versions/2.4.2/bin/bundle update mysql2` - **What did you expect to happen?** I expected Bundler to... - **What happened instead?** Instead, what happened was... - **Have you tried any solutions posted on similar issues in our issue tracker, stack overflow, or google?** I tried... - **Have you read our issues document, https://github.com/bundler/bundler/blob/master/doc/contributing/ISSUES.md?** ...
とさらにエラーが出ました。
$ gem list --local | grep mysql2
としてみたらやはりmysql2が入っていなかったため、
$ gem install mysql2
としてインストールを試みました。
すると
Fetching: mysql2-0.4.10.gem (100%) Building native extensions. This could take a while... /home/kagerou/.rbenv/versions/2.4.2/lib/ruby/2.4.0/rubygems/ext/builder.rb:76: warning: Insecure world writable dir /home/kagerou/.rbenv/versions in PATH, mode 040777 ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. current directory: /home/kagerou/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/ext/mysql2 (略) mysql client is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try again.
てことで、そもそもmysqlのライブラリが必要。
ここからrootになって作業します。
sudo su - apt-get install libmysqlclient-dev
その後、一般ユーザーに戻り
$ gem install mysql2
としたら上手くいきました。