11
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

【AmazonLinux2】MySQL2のGemをインストールする際にエラー

MySQLの調子が悪かったのでアンインストールして再インストール

gem uninstall mysql2
gem install mysql2
  • エラーが発生
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/takumi/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3/ext/mysql2
/home/takumi/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20200619-26162-iq2nwv.rb extconf.rb --with-ldflags=-L/usr/local/opt/openssl/lib
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/takumi/.rbenv/versions/2.5.1/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/takumi/.rbenv/versions/2.5.1/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/takumi/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3 for inspection.
Results logged to /home/takumi/.rbenv/versions/2.5.1/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

言われた通り下記のコマンドを実行してもエラーが発生した。

gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'

解決策

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.

エラー文にある、この中の'sudo yum install mysql-devel'を実行した。

$ sudo yum install mysql-devel
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                                                                                         | 3.7 kB  00:00:00     
amzn2extra-docker                                                                                                                                                                  | 3.0 kB  00:00:00     
amzn2extra-nginx1                                                                                                                                                                  | 1.8 kB  00:00:00     
mysql-connectors-community                                                                                                                                                         | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                                                              | 2.5 kB  00:00:00     
mysql57-community                                                                                                                                                                  | 2.5 kB  00:00:00     
nodesource                                                                                                                                                                         | 2.5 kB  00:00:00     
33 packages excluded due to repository priority protections
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ mysql-community-devel.x86_64 0:5.7.30-1.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

==========================================================================================================================================================================================================
 Package                                                アーキテクチャー                        バージョン                                       リポジトリー                                        容量
==========================================================================================================================================================================================================
インストール中:
 mysql-community-devel                                  x86_64                                  5.7.30-1.el7                                     mysql57-community                                  3.7 M

トランザクションの要約
==========================================================================================================================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 3.7 M
インストール容量: 20 M
Is this ok [y/d/N]: y
Downloading packages:
mysql-community-devel-5.7.30-1.el7.x86_64.rpm                                                                                                                                      | 3.7 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : mysql-community-devel-5.7.30-1.el7.x86_64                                                                                                                                 1/1 
  検証中                  : mysql-community-devel-5.7.30-1.el7.x86_64                                                                                                                                 1/1 

インストール:
  mysql-community-devel.x86_64 0:5.7.30-1.el7                                                                                                                                                             

完了しました!

bundle installを実行。無事通りました!

$ bundle install
~~
Bundle complete! 37 Gemfile dependencies, 136 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
11
Help us understand the problem. What are the problem?