環境
macOS Big Sur(11.2)
ruby
rails6.1.4
mysql2
gemでmysql2インストール時、絶対errorに俺はなる
以前はQiitaに対処方法のエントリがあったのだけど、なんか無くなっちゃったので。
Gem::Ext::BuildError: ERROR: Failed to build gem native
extension.
.....
An error occurred while installing mysql2 (0.5.3),
and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source
'https://rubygems.org/'` succeeds before bundling.
解決法
ターミナルで下記を打ち込む。
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
Gemfileに下記をかいて、bundle installする。
Gemfile
gem 'mysql2', '~>0.5.3'
以上です。