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 an error occurs when nokogiri enters when bundle install
What to do if you install Ubuntu
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
What to do if you accidentally create a model
What to do if an ActionController :: UnknownFormat error occurs
What to do if you get a SQLite3 :: BusyException: database is locked error
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
What to do after Vagrant install
What to do if you get a port error when docker-compose up on Mac
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
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
[Note] What to do if bundle install in Chapter 3 of the rails tutorial is not possible
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 get an error during rails db: reset
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do if you get an uninitialized constant Likes Controller error
What to do if you can't install the plugin from the Eclipse marketplace
What to do and how to install when an error occurs in DXRuby 1.4.7
no space left on device What to do if an error occurs
What to do if you get an error when you hit Heroku logs
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 an error occurs in VS Code when importing a django module or your own module installed by pip install
What to do if you get Could not locate Gemfile or .bundle / directory
What to do if you get the error message unrecognized selector send to instance "***"
What to do if you get an error on heroku rake db: migrate
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
How to install MySQL
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
What to do when rails creates a 〇〇 2.rb file
What to do if password authentication fails in Docker/Postgres
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 the error Couldn't find Item without an ID
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