mysql2 Rails環境構築時にbundle installでエラーが出た時に解決した話
bundle install でmysql2が入らずちょっと困りました。 ぐぐって先人の知恵をお借りして解決したので、ログとして記します。
大変お世話になりました!
mysql2 gemインストール時のトラブルシュート - Qiita
バージョン
解決コマンド
$ gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
私の場合は下記のようにPermissionエラーになりました。
$ gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib ERROR: While executing gem ... (Errno::EACCES) Permission denied @ rb_sysopen - /Users/hoge/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/CHANGELOG.md M
ので、sudo
をつけて権限を強めて通したところ、通りました。
$ sudo gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib Building native extensions with: '--with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib' This could take a while... Successfully installed mysql2-0.5.2 1 gem installed
無事インストールできたので、再度bundle
を叩いたところ、Bundle complete! できました。やったね
毎日感謝です!
【追記】またつまずいたけど、同じ方法でなんとかならなかった時に叩いたコマンド
そんな時こちらを叩きました。
$ bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include" $ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
そのあとに
$ bundle install
これで通りました。
やっている事は同じな様な気もしますが、設定ファイルに書いたことで、次にbundle install
を叩いた時いちいちパスワード聞かれることがなくて楽でした。