LoginSignup
4
1

More than 3 years have passed since last update.

【EC2】bundle install時、mysql2でエラーがでた件

Posted at

背景

EC2上で、bundle install を実行したらエラーが発生したのでメモ。

「mysql2(0.5.3)のインストール中にエラーが発生し、Bundlerを続行できません。」という内容で、パッケージの依存を解決することで解消しました。

エラー内容

EC2でbundle installを行うと下記のようなエラーが発生。

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

    current directory: /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
/home/ec2-user/.rbenv/versions/2.6.5/bin/ruby -I /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r ./siteconf20210403-11662-qkup4a.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/ec2-user/.rbenv/versions/2.6.5/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/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

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

仮説(考えたこと)

  • mysql2 0.5.3 をインストールできないよっていうエラー内容
  • 以下のエラー文からパッケージ関係のエラーであることがわかった
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

EC上で実行

$ bundle install

解決!

実行内容の意味

sudo yum install mysql-devel
sudo => rootレベルの特権
yum => パッケージ(各種ソフトをインストールするときのひとかたまりの単位)を管理するコマンド
install => installする
mysql-devel=> インストールする対象のパッケージ(=ファイル群)の名前

'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev'

apt-get => パッケージの操作・管理を行うコマンド

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1