bundle install failed (continued). The case caused by gem "MySQL2".

background </ font>

It is a continuation of libv8. I got the following error when installing the gem of Mysql.

Installing mysql2 0.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

environment </ font>

item Contents
OS.Catalina v10.15.4
Ruby v2.5.1
Ruby On Rails v5.2.4.3
MySQL v5.6

Contents </ font>

** Correspondence 1) Reinstall Mysql gem ** CMD>gem uninstall mysql2

Successfully uninstalled mysql2-0.4.10

CMD>gem install mysql2

Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

Even if I bundle install, it fails.

** Correspondence 2) Set environment variables and reinstall ** Execute the following command to change the environment variables

CMD>export PATH="/usr/local/opt/[email protected]/bin:$PATH"
CMD>export DYLD_LIBRARY_PATH="/usr/local/opt/[email protected]/:$DYLD_LIBRARY_PATH"
CMD>export LDFLAGS="-L/usr/local/opt/openssl/lib"
CMD>export CPPFLAGS="-I/usr/local/opt/openssl/include"

Checking environment variables

[\W staff@term]env
(abridgement)
LDFLAGS=-L/usr/local/opt/openssl/lib
CPPFLAGS=-I/usr/local/opt/openssl/include

→ After changing the environment variables, I couldn't do "bundle install" in the same way.

** Correspondence 3) After all, change the bundler settings **

CMD>bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

Now, "bundle install" is finally working.

Reference article </ font>

MySQL couldn't bundle install in Rails project Revert to v5.7 because v8 was installed by brew upgrade mysql and rails server does not start What to do if "ld: library not found for -l imported_openssl" is displayed when installing mysql2 Troubleshooting when installing mysql2 gem