LoginSignup
3
3

More than 3 years have passed since last update.

【Mac】bundle installでmysql2が入らないときの対策コマンド

Last updated at Posted at 2019-12-06

◆現象

bundle installをすると次のようなエラーが出てmysql2が上手く入らない。

〜省略〜
current directory: /Users/hogehoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/hogehoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2 for inspection.
Results logged to /Users/hogehoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0/mysql2-0.5.2/gem_make.out

An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

●エラーで言われていること

ld: library not found for -lssl

ライブラリ(mysql2を入れるのに必要なもの)が見つからないと言われている。ライブラリが見つかるよう指定してあげると解決できる。

◆対策コマンド

ターミナルで次のコマンドを実行してから再度bundle installをする。

bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"

これでbundlerを使ってmysql2を入れる際、以下のような場所にあるライブラリを使ってくれるようになる。

brew --prefix openssl
=> /usr/local/opt/openssl@1.1
3
3
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
3
3