14
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-12-22

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]

症状

いつも通りgemを入れていく…

$ bundle install
Fetching gem metadata from https://rubygems.org/..........
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/mysql2.so
/usr/bin/ld: -lmariadb が見つかりません
collect2: エラー: ld はステータス 1 で終了しました
make: *** [mysql2.so] エラー 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
/home/sabamotto/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/mysql2-0.4.9/gem_make.out

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:
  mysql2

mariadbにリンク出来ない…
(LANG=C環境では/usr/bin/ld: cannot find -lmariadb

原因

gem mysql2の issue#877 に似たようなものがあった。この問題は既にmysql2 0.4.10でマージされたようなので、bundle updateで対応した。
しかし、それでも解決しなかったので色々試みたところ、MariaDB-sharedが入っていないことも原因だった。MariaDB-develだけではダメなようだ。

解決策

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

$ bundle update
Fetching gem metadata from https://rubygems.org/..........

...

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はライブラリのインストールで躓くことが多い気がする… :(

14
6
1

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
14
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?