RailsでMariaDBを使用したいと思ってbundle installしたときに出たエラーです。
MariaDBのバージョンは10系
OSはUbuntu14.04です。
bundle installしたときのエラー
$ bundle install --path vendor/bundle Fetching gem metadata from https://rubygems.org/........... Resolving dependencies... Using rake 10.3.2 〜中略〜 Using jquery-rails 3.1.1 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /home/foo/.rbenv/versions/2.1.2/bin/ruby extconf.rb checking for ruby/thread.h... yes 〜中略〜 checking for mysql_query() in -lmysqlclient... no *** 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-mysqlclientlib extconf failed, exit code 1 Gem files will remain installed in /home/foo/path/to/project/vendor/bundle/ruby/2.1.0/gems/mysql2-0.3.16 for inspection. Results logged to /home/foo/path/to/project/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.16/gem_make.out An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.
mysql2をgemでインストールしろと書いてあったので実行しました。
$ gem install mysql2 -v '0.3.16' Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. /home/foo/.rbenv/versions/2.1.2/bin/ruby extconf.rb checking for ruby/thread.h... yes 〜中略〜 checking for mysql_query() in -lmysqlclient... no *** 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-mysqlclientlib extconf failed, exit code 1 Gem files will remain installed in /home/foo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.16 for inspection. Results logged to /home/foo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.16/gem_make.out
同じエラーが出て失敗しました。
エラーメッセージで検索したら下記のサイトでlibmysqld-devをインストールすると
書いてあったので、インストール
gem install mysql2 でエラー - てしりこじり
$ sudo apt-get install libmysqld-dev パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 インストールすることができないパッケージがありました。おそらく、あり得 ない状況を要求したか、(不安定版ディストリビューションを使用しているの であれば) 必要なパッケージがまだ作成されていなかったり Incoming から移 動されていないことが考えられます。 以下の情報がこの問題を解決するために役立つかもしれません: 以下のパッケージには満たせない依存関係があります: libmysqld-dev : 依存: libmysqlclient-dev (>= 5.5.38-0ubuntu0.14.04.1) E: 問題を解決することができません。壊れた変更禁止パッケージがあります。
パッケージ依存問題が起きてエラーが起きました。
今回は、MariaDBを使っているので、libmariadbclient-devを入れれば、
MariaDBのlibmysqld-dev相当のものがインストールされるようです。
Use MariaDB instead of MySQL in my Rails project - Stack Overflow
$ sudo apt-get install libmariadbclient-dev 以下の新規パッケージがインストールされます: libmariadbclient-dev 0 個のパッケージを更新、 1 個を新たにインストール、 0 個を削除予定、0 個が更新されていない。 1,395 k バイトのアーカイブを取得する必要があります。 展開後に 8,273 k バイトのディスク領域が新たに消費されます。 取得: 1 http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/10.0/ubuntu/ trusty/main libmariadbclient-dev amd64 10.0.13+maria-1~trusty [1,395 kB] Fetched 1,395 kB in 0秒 (3,271 kB/s) 以前に未選択のパッケージ libmariadbclient-dev を選択しています。 (データベースを読み込んでいます ... 現在 340660 個のファイルとディレクトリがインストールされています。) Preparing to unpack .../libmariadbclient-dev_10.0.13+maria-1~trusty_amd64.deb ... Unpacking libmariadbclient-dev (10.0.13+maria-1~trusty) ... Processing triggers for man-db (2.6.7.1-1) ... libmariadbclient-dev (10.0.13+maria-1~trusty) を設定しています ...
改めて、mysql2をインストール
$ gem install mysql2 Building native extensions. This could take a while... Successfully installed mysql2-0.3.16 Parsing documentation for mysql2-0.3.16 Installing ri documentation for mysql2-0.3.16 Done installing documentation for mysql2 after 0 seconds 1 gem installed
うまくいったので、改めてbundle install
$ bundle install --path vendor/bundle Fetching gem metadata from https://rubygems.org/........... Resolving dependencies... Using rake 10.3.2 Using i18n 0.6.11 Using json 1.8.1 Using minitest 5.4.0 Using thread_safe 0.3.4 Using tzinfo 1.2.2 Using activesupport 4.1.5 Using builder 3.2.2 Using erubis 2.7.0 Using actionview 4.1.5 Using rack 1.5.2 Using rack-test 0.6.2 Using actionpack 4.1.5 Using mime-types 1.25.1 Using polyglot 0.3.5 Using treetop 1.4.15 Using mail 2.5.4 Using actionmailer 4.1.5 Using activemodel 4.1.5 Using arel 5.0.1.20140414130214 Using activerecord 4.1.5 Using bundler 1.7.2 Using coffee-script-source 1.8.0 Using execjs 2.2.1 Using coffee-script 2.3.0 Using thor 0.19.1 Using railties 4.1.5 Using coffee-rails 4.0.1 Using hike 1.2.3 Using multi_json 1.10.1 Using jbuilder 2.1.3 Using jquery-rails 3.1.1 Installing mysql2 0.3.16 Using tilt 1.4.1 Using sprockets 2.11.0 Using sprockets-rails 2.1.3 Using rails 4.1.5 Using rdoc 4.1.1 Using sass 3.2.19 Using sass-rails 4.0.3 Using sdoc 0.4.1 Using spring 1.1.3 Installing turbolinks 2.3.0 Installing uglifier 2.5.3 Your bundle is complete! It was installed into ./vendor/bundle
通りました。
gem install mysql2 on Debian Wheezy with MariaDB 10 | BeezNest Open-Source specialists
こちらのサイトではlibmariadbd-devをインストールするように書いてあります。
多分、libmariadbclient-devを入れれば、libmariadbd-devが一緒に入ったんだと思っています。