Copying the repository and getting a mysql2 error on the first bundle install

environment

Ruby 2.5.7 Rails 5.2.4

Background

This is an article for my memo, but I couldn't find an article explaining this error. I hope it will be helpful to anyone.

For learning, I tried to change the template engine of the Rails application I'm currently writing from erb to slim. It was going to be a heavy refurbishment, so leave the existing application as it is, make a copy and slim it.

Qiita --Push the cloned repository remotely as a separate repository

Copying of GitHub repository and application is completed, and when I try bundle install in the copied app directory for slim, the following error occurs. (At this point, there is no error in the copy source application.)

$ 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/.........

...
Using gem list
...

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: /home/vagrant/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3/ext/mysql2
/home/vagrant/.rbenv/versions/2.5.7/bin/ruby -r ./siteconf20200915-19570-14xz74g.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
checking for -lmysqlclient... no
-----
mysql client is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev' or 'sudo yum install mysql-devel', and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/vagrant/.rbenv/versions/2.5.7/bin/$(RUBY_BASE_NAME)
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/vagrant/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/vagrant/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3 for inspection.
Results logged to /home/vagrant/.rbenv/versions/2.5.7/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.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

mysql client is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev' or 'sudo yum install mysql-devel', and try again.

I'm asked to try this sentence of error and 3 patterns of commands, so I'll try them in order.

$ sudo apt-get install libmariadb-dev
sudo: apt-get: command not found

ʻI was told that the apt-getcommand could not be found, so skip the second'sudo apt-get install libmysqlclient-dev' and try the third'sudo yum install mysql-devel'` ..

$ sudo yum install mysql-devel
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
base                                                                                                                                                                   | 3.6 kB  00:00:00
extras                                                                                                                                                                 | 2.9 kB  00:00:00
nodesource                                                                                                                                                             | 2.5 kB  00:00:00
updates                                                                                                                                                                | 2.9 kB  00:00:00
(1/3): extras/7/x86_64/primary_db                                                                                                                                      | 206 kB  00:00:00
(2/3): updates/7/x86_64/primary_db                                                                                                                                     | 4.5 MB  00:00:00
(3/3): nodesource/x86_64/primary_db                                                                                                                                    |  43 kB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.65-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================
 Package                                          Arch                                      Version                                             Repository                               Size
==============================================================================================================================================================================================
Installing:
 mariadb-devel                                    x86_64                                    1:5.5.65-1.el7                                      base                                    756 k

Transaction Summary
==============================================================================================================================================================================================
Install  1 Package

Total download size: 756 k
Installed size: 3.3 M
Is this ok [y/d/N]: y
Downloading packages:
mariadb-devel-5.5.65-1.el7.x86_64.rpm                                                                                                                                  | 756 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mariadb-devel-5.5.65-1.el7.x86_64                                                                                                                                        1/1
  Verifying  : 1:mariadb-devel-5.5.65-1.el7.x86_64                                                                                                                                        1/1

Installed:
  mariadb-devel.x86_64 1:5.5.65-1.el7

Complete!

You will be asked if you want to download the package on the way, so enter y and press Enter.

The mysql-devel entered in the command is the package management system required to run mysql on the server, and this time the missing mariadb-devel is downloaded.

Download completed normally, again

$bundle install

When you do, it completes normally.

Summary

I could understand the package management system, but I couldn't understand how mariadb-devel was involved in this error, so I would appreciate it if you could let me know in the comments.

Also, if you have any questions, differences in interpretation, or if you feel something is wrong with the description method, we would appreciate it if you could point it out in the comments.

Thank you for reading until the end.

Reference site

Qiita --Push the cloned repository remotely as a separate repository Hatena Blog-Install MySQL on CentOS

Recommended Posts

Copying the repository and getting a mysql2 error on the first bundle install
What to do if mysql2 gets a bundle install error
Install the memcached plugin on MySQL and access it from Java
bundle install error
bundle install error
About the error caused by bundle install ~ puma Gem ~
Install MySQL 5.6 on CentOS6 [How to specify the version]
Error when bundle install
I changed the Ruby version and now I can't bundle install
bundle install failed (continued). The case caused by gem "MySQL2".
[Rails] What is the difference between bundle install and bundle update?
[Ruby on Rails] bundle install fails "An error occurred while installing pg (1.2.3), and Bundler cannot continue."
bundle install does not install mysql2
Difference between bundle and bundle install
Create a private repository in Amazon ECR and push/pull the image
How to install and configure the monitoring tool "Graphite" on Ubuntu
Install Rails in the development environment and create a new application
Install Ubuntu20.04 on RaspberryPi 4 and build Kubernetes to run the container
I don't see an error in Rails bundle install ... the solution
If the bundle install command on the Docker container ends with an error at code: 15, check the BUNDLE_PATH setting