0

Ruby on Railsでプロジェクトを作成し、bundle installを実行しました。
そこで、mysql2がインストール中にエラーを起こしたと表示されました。
そこでmkmf.logからmysql2に関するファイルを開こうとしたのですが、ファイルを開くコマンドが分かりませんでした。
mkmf.logの開き方と、mysql2のエラーの内容を教えて頂きたいです。
どうか宜しくお願いいたします。

・gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.1'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.5'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

・エラー内容

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

    current directory: /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.5/ext/mysql2
/home/ubuntu/.rvm/rubies/ruby-3.0.0/bin/ruby -I /home/ubuntu/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0 -r ./siteconf20230726-3893-8378x1.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
*** 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/ubuntu/.rvm/rubies/ruby-3.0.0/bin/$(RUBY_BASE_NAME)
        --with-openssl-dir
        --without-openssl-dir
        --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-mysqlclient-dir
        --without-mysqlclient-dir
        --with-mysqlclient-include
        --without-mysqlclient-include=${mysqlclient-dir}/include
        --with-mysqlclient-lib
        --without-mysqlclient-lib=${mysqlclient-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
/home/ubuntu/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/mkmf.rb:1050:in `block in find_library': undefined method `split' for nil:NilClass
(NoMethodError)
        from /home/ubuntu/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/mkmf.rb:1050:in `collect'
        from /home/ubuntu/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/mkmf.rb:1050:in `find_library'
        from extconf.rb:131:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/ubuntu/.rvm/gems/ruby-3.0.0/gems/mysql2-0.5.5 for inspection.
Results logged to /home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.5/gem_make.out

An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.5' --source 'https://rubygems.org/'` succeeds before bundling.

mkmf.log

ubuntu:~/environment/myapp (master) $ find ~/.rvm -name mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.5/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/nio4r-2.5.9/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/racc-1.7.1/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/msgpack-1.7.2/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/date-3.3.3/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.3/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/ffi-1.15.5/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.6/extensions/x86_64-linux/3.0.0/mysql2-0.5.5/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.6/extensions/x86_64-linux/3.0.0/nio4r-2.5.9/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.6/extensions/x86_64-linux/3.0.0/racc-1.7.1/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.6/extensions/x86_64-linux/3.0.0/msgpack-1.7.2/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.6/extensions/x86_64-linux/3.0.0/date-3.3.3/mkmf.log
/home/ubuntu/.rvm/gems/ruby-3.0.6/extensions/x86_64-linux/3.0.0/ffi-1.15.5/mkmf.log

バージョン
ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
rails: Could not find gem 'rails (~> 6.1.3, >= 6.1.3.1)' in any of the gem sources
listed in your Gemfile.
Run bundle install to install missing gems.

1 件の回答 1

2

mkmf.logの開き方と、

エラーメッセージをよく読んでください。

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.5/mkmf.log

extconf failed, exit code 1

上のように明確にmkmf.logへのフルパスが書いてあります。そのフルパスを指定して、

more /home/ubuntu/.rvm/gems/ruby-3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.5/mkmf.log

とすれば、mkmf.logは開けます。


mysql2のエラーの内容を教えて頂きたいです。

これは、「mysql2のエラー」では無く、mysql2 gemのインストールのエラーです。

mysql2 gemのextconf.rbの131行目でfind_library('mysqlclient', nil, usr_local_lib, "#{usr_local_lib}/mysql")の呼び出しがありますが、このusr_local_libnilであるため、find_libaryの呼び出しが失敗します。この現象が起きるのは、MariaDBやMySQLのクライアントライブラリやヘッダが見つからず、--with-mysql-dir等でその場所を指定しなかった場合に発生します。次の事を確認してください。

  1. MySQLまたはMySQLのクライアントライブラリとヘッダをインストールしていない場合は、インストールしてください。インストール方法はOSやインストール対象によって異なります。可能な限り、サーバーと同じソフトウェア、同じバージョンを推奨します。

  2. もし、既にインストールしている場合は、--with-mysql-dir=インストールしたパスを指定してgem installを行ってみてください。

各OS毎の注意事項はREADME.mdも参考にしてください。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。