0
0

More than 1 year has passed since last update.

bundle install で `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/' と言われてうまくいかない

Last updated at Posted at 2022-08-22

時間ないので、雑に忘備録として、一旦あげておきます

問題

gem 'mysql2', '~> 0.5.3'

こんな感じでGemfileにmysql2を入れようとしたときに

bin/bundle install

って入れても

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.

In Gemfile:
  mysql2

こんなエラーが出るわけですよね。

書いてある通りに

gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/

と入れても

ld: library not found for -lssl

こんな感じでエラーが出るわけです。。。

解決法

オプションで次のように記述すると解決できました。

gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

そしたらbundle installはうまくいくと思います。
-v '0.5.3'の部分は、自分のエラーに合わせたバージョンにするといいと思います。
例)バージョン0.5.1の場合→gem install mysql2 -v '0.5.1' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

bin/bundle install
...
...
...
Bundle complete! 46 Gemfile dependencies, 138 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

僕の場合はこんな感じでした。

環境

M1 Mac(2020)
Big Sur v.11.6.1

Rails 7.0.2.3
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]

何か指摘があればお願いします。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0