LoginSignup
2
2

More than 5 years have passed since last update.

gem install mysql2 エラーの対策

Posted at

経緯

ruby で MySQLを操作するためのプログラムを書きたくて、gemのmysql2をインストールしようとした際にハマったので自分のための備忘録。

環境

Ubuntu16.04
ruby2.3

エラー

admin@hoge:/usr/local/share/update_pdns$ sudo bundle install --path vender/bundle
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Fetching gem metadata from https://rubygems.org/..............
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Using concurrent-ruby 1.0.5
Using i18n 0.8.1
Using minitest 5.10.1
Using thread_safe 0.3.6
Using arel 7.1.4
Using mime-types-data 3.2016.0521
Installing mysql2 0.4.5 with native extensions
Using bundler 1.14.5
Using tzinfo 1.2.2
Using mime-types 3.1
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/share/update_pdns/vender/bundle/ruby/2.3.0/gems/mysql2-0.4.5/ext/mysql2
/usr/bin/ruby2.3 -r ./siteconf20170303-8868-1xsjnvm.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /usr/local/share/update_pdns/vender/bundle/ruby/2.3.0/gems/mysql2-0.4.5 for inspection.
Results logged to /usr/local/share/update_pdns/vender/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/mysql2-0.4.5/gem_make.out

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

mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

どうやら rubyのヘッダーファイルが見つからないとのこと。

対策

$sudo aptitude install ruby-dev

ruby-devパッケージにヘッダーファイルが格納されてるらしい。
これをインストールしたら解決しました!

参考 URL

2
2
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
2
2