[Rails 6] MySQL 2 cannot be bundle install

When I make a new application with Rails6 and bundle install it, I get the following error and cannot bundle install.

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

    current directory: /Users/jun/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
/Users/jun/.rbenv/versions/2.6.5/bin/ruby -I /Users/jun/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r ./siteconf20200830-5266-esdr5q.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
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.21/lib
-----
creating Makefile

current directory: /Users/jun/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/jun/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/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/jun/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/jun/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-19/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.

In Gemfile:
  mysql2

solution

Execute the following command

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

I passed when I did bundle install

$ bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.1
Using concurrent-ruby 1.1.7
Using i18n 1.8.5
Using minitest 5.14.1
Using thread_safe 0.3.6
Using tzinfo 1.2.7
Using zeitwerk 2.4.0
Using activesupport 6.0.3.2
Using builder 3.2.4
Using erubi 1.9.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.10
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.7.0
Using rails-html-sanitizer 1.3.0
Using actionview 6.0.3.2
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 6.0.3.2
Using nio4r 2.5.2
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.3
Using actioncable 6.0.3.2
Using globalid 0.4.2
Using activejob 6.0.3.2
Using activemodel 6.0.3.2
Using activerecord 6.0.3.2
Using mimemagic 0.3.5
Using marcel 0.3.3
Using activestorage 6.0.3.2
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailbox 6.0.3.2
Using actionmailer 6.0.3.2
Using actiontext 6.0.3.2
Using public_suffix 4.0.5
Using addressable 2.7.0
Using bindex 0.8.1
Using msgpack 1.3.3
Using bootsnap 1.4.8
Using bundler 2.1.4
Using byebug 11.1.3
Using regexp_parser 1.7.1
Using xpath 3.2.0
Using capybara 3.33.0
Using childprocess 3.0.0
Using ffi 1.13.1
Using jbuilder 2.10.0
Using rb-fsevent 0.10.4
Using rb-inotify 0.10.1
Using listen 3.2.1
Using method_source 1.0.0
Fetching mysql2 0.5.3
Installing mysql2 0.5.3 with native extensions
Using puma 4.3.5
Fetching rack-proxy 0.6.5
Installing rack-proxy 0.6.5
Using thor 1.0.1
Using railties 6.0.3.2
Using sprockets 4.0.2
Using sprockets-rails 3.2.1
Using rails 6.0.3.2
Using rubyzip 2.3.0
Using sassc 2.4.0
Using tilt 2.0.10
Using sassc-rails 2.1.2
Using sass-rails 6.0.0
Using selenium-webdriver 3.142.7
Using spring 2.1.1
Using spring-watcher-listen 2.0.1
Using turbolinks-source 5.2.0
Using turbolinks 5.2.1
Using web-console 4.0.4
Fetching webdrivers 4.4.1
Installing webdrivers 4.4.1
Fetching webpacker 4.3.0
Installing webpacker 4.3.0
Bundle complete! 17 Gemfile dependencies, 74 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

reference https://qiita.com/fukuda_fu/items/463a39406ce713396403 https://stackoverflow.com/questions/6935146/bundle-update-install-fail-after-os-x-lion-upgrade-rails-3/26203229

Recommended Posts

[Rails 6] MySQL 2 cannot be bundle install
bundle install does not install mysql2
Rails new fails to install mysql
mysql2 fails to install with bundle install
[Rails] Rails new cannot be done from Docker
[Rails] Posts cannot be deleted when commented! ??
[Windows] gem install sqlite3 cannot be done
Rails server cannot be started in Cloud9
I get an error with bundle install and puma cannot be installed.
bundle install error
bundle install error
[Rails] Could not locate Gemfile with bundle install
[Rails 6] method :: delete cannot be used with link_to
Error in bundle install when running rails new
Rails error messages cannot be translated into Japanese
Bundle install with docker + rails6 does not reflect gem
Mac Rails Install Error
Error when bundle install
How to install MySQL
After setting database to mysql, bundle install causes an error
bundle install failed (continued). The case caused by gem "MySQL2".
[Rails] What is the difference between bundle install and bundle update?
Note when pip install mysqlclient cannot be installed on Mac
Windows10 "rails s" cannot be started. Unable to access localhost: 3000
[rails] Problems that cannot be registered / logged in with devise
What to do if mysql2 gets a bundle install error
[Ruby on Rails] bundle install fails "An error occurred while installing pg (1.2.3), and Bundler cannot continue."
Rails6 (MySQL, Ubuntu environment, Cloud9)
Install Sidekiq pro on Rails
Because getSupportLoaderManager cannot be used
[Rails] How to install devise
(For beginners) [Rails] Install Devise
Install Rails on macOS Catalina
Java Stream cannot be reused.
Difference between bundle and bundle install
[Rails / MySQL] Mac environment construction
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
React.js CSS in Rails app deployed on EC2 cannot be loaded
I want to add devise in Rails, but I can't bundle install
I don't see an error in Rails bundle install ... the solution
Rails tutorial When rails new cannot be done due to different versions