What to do if mysql2 gets a bundle install error

Prerequisites

mac OS Rails 6.0.3.2 ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin19]

problem

When I was creating a project in a local environment while looking at the teaching materials of a certain online school, the following error occurred in bundle install.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/ebinashohei/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
/Users/ebinashohei/.rbenv/versions/2.6.3/bin/ruby -I /Users/ebinashohei/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20200622-74325-qvfli8.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.19_1/lib
-----
creating Makefile

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

current directory: /Users/ebinashohei/.rbenv/versions/2.6.3/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/ebinashohei/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/ebinashohei/.rbenv/versions/2.6.3/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

Since it solved a similar error, it is shown below.

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

Reference site https://qiita.com/SAYJOY/items/dd7c8fc7a3647e7ff969

Recommended Posts

What to do if mysql2 gets a bundle install error
Add gem'rails-i18n','~> 6.0.0' and what to do if bundle install gives an error
What to do if you accidentally create a model
What to do if an ActionController :: UnknownFormat error occurs
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
After setting database to mysql, bundle install causes an error
What to do if you get a java.io.IOException in GlassFish
mysql2 fails to install with bundle install
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
What to do if you get a "302" error in your controller unit test code in Rails
What to do if you get angry with OpenSSL with pyenv install
What to do when a javax.el.PropertyNotWritableException occurs
bundle install error
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if an error occurs when doing npm install axios in React + Typescript project
What to do if you get a groovy warning in Thymeleaf Layout
What to do if you can't install the plugin from the Eclipse marketplace
no space left on device What to do if an error occurs
Copying the repository and getting a mysql2 error on the first bundle install
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do if the server tomcat dies
Error with bundle install after upgrading to Catalina
What to do if you push incorrect information
What to do if mvn archetype: generate fails
What to do if the image posted by refile disappears after setting a 404 error page in Rails
What to do if you get Could not locate Gemfile or .bundle / directory
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`
[Ubuntu] What to do when MongoDB cannot be started due to a SocketException error
What to do if you get an "A server is already running." Error when you try to start the rails server
Error when bundle install
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do if ClassNotFoundException occurs when starting Tomcat
What to do if rails server can't be stopped
What to do if TextToSpeech doesn't work on Android 11
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do if Failure / Error: require File.expand_path ('../ config / environment', __dir__) appears in RSpec
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
bundle install does not install mysql2
What to do if FacesMessage is set but not displayed
[Rails] What to do if you can't get an error message with the errors method
What to do if the adb command cannot be executed
What to do if you get an error in Basic authentication during Rails test code
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
What to do if you can't use the rails command
[Rails 6] What to do when a missing a template error occurs after introducing haml [Super easy]
What to do if you go offline due to SSL certificate error when running Jenkins on Mac
What to do if an SSH key authentication error occurs during automatic deployment to EC2 with Capistrano
[Java] What to do if a lot of "File is opened too much" is displayed due to FileNotFoundException
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do about the "cannot be read or is not a valid ZIP file" error
[Ubuntu 20.04] What to do if the external monitor is not recognized
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
[Rails] What to do if data is not registered in DB
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What to do if Cloud9 is full in the Rails tutorial
[Logback] What to do if unnecessary files do not disappear during rotation
What to do when you become a Problem During Content Assist