More than 3 years have passed since last update.

posted at

updated at

CentOS7+MariaDB10でgem mysql2がエラーになる

CentOS7.4上でMariaDB10とRails5のアプリケーションをインストールしようとしたが、bundle installで躓いたので解決策を書いておく。
結論だけ先に言うとbundle updateyum install -y MariaDB-sharedで解決した。


$ cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)

$ mysql --version
mysql  Ver 15.1 Distrib 10.2.11-MariaDB, for Linux (x86_64) using readline 5.1

$ ruby -v
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]



$ bundle install
Fetching gem metadata from
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.6
Using minitest 5.10.3


Fetching mysql2 0.4.9
Installing mysql2 0.4.9 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/sabamotto/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/mysql2-0.4.9/ext/mysql2
/home/sabamotto/.rbenv/versions/2.4.3/bin/ruby -r ./siteconf20171223-19752-eo01fi.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes


linking shared-object mysql2/
/usr/bin/ld: -lmariadb が見つかりません
collect2: エラー: ld はステータス 1 で終了しました
make: *** [] エラー 1

make failed, exit code 2

Gem files will remain installed in /home/sabamotto/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/mysql2-0.4.9 for inspection.
Results logged to

An error occurred while installing mysql2 (0.4.9), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.4.9'` succeeds before bundling.

In Gemfile:

(LANG=C環境では/usr/bin/ld: cannot find -lmariadb


gem mysql2の issue#877 に似たようなものがあった。この問題は既にmysql2 0.4.10でマージされたようなので、bundle updateで対応した。


$ sudo yum install -y MariaDB-devel MariaDB-shared

$ bundle update
Fetching gem metadata from


Fetching mysql2 0.4.10
Installing mysql2 0.4.10


Fetching turbolinks 5.0.1
Installing turbolinks 5.0.1
Fetching uglifier 4.0.2
Installing uglifier 4.0.2
Fetching web-console 3.5.1
Installing web-console 3.5.1
Bundle complete! 44 Gemfile dependencies, 124 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

rubyはライブラリのインストールで躓くことが多い気がする… :(

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
What you can do with signing up