$ rails _5.2.4.1_ new appname --database=mysql --skip-test --skip-turbolinks --skip-bundle
でrailsアプリを新規作成した後、
$ bundle install
...
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql/8.0.19/lib
-----
...
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/machoair/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to
/Users/machoair/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-17/2.6.0/mysql2-0.5.3/gem_make.out
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.
のエラーが発生
解決策
上記の通り、エラー内容は
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
Setting libpath to /usr/local/Cellar/mysql/8.0.19/lib
ld: library not found for -lssl
私もよく理解していませんが、「libssl.dylib」を探そうとして、「/usr/local/Cellar/mysql/8.0.19/lib」を探したがありませんというエラーらしいです。
【Rails】MySQL2がbundle installできない時の対応方法
https://qiita.com/fukuda_fu/items/463a39406ce713396403
の記事を参考に、
$ cd アプリ場所
$ brew info openssl
...
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" #ここを参考に次のコマンドを書く
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" #ここを参考に次のコマンドを書く
...
$ bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl@1.1/include"
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl@1.1/lib"
You are replacing the current local value of build.mysql2, which is currently "--with-cppflags=-I/usr/local/opt/openssl@1.1/include"
$ bundle install
で解決しました!