解決したいこと
今Railsのアプリをmysql2を使用しデプロイしようとしたのですが、
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2
/home/ec2-user/.rbenv/versions/2.7.6/bin/ruby -I
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0 -r
./siteconf20231211-19703-1jgj6jw.rb extconf.rb
--with-mysql-config\=/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2
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... no
-----
Using mysql_config at
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2
-----
*** 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/ec2-user/.rbenv/versions/2.7.6/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
extconf.rb:118:in ``': Permission denied -
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5/ext/mysql2
(Errno::EACCES)
from extconf.rb:118:in `<main>'
To see why this extension failed to compile, please check the mkmf.log
which can be found here:
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/mysql2-0.5.5/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.5 for
inspection.
Results logged to
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/mysql2-0.5.5/gem_make.out
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:99:in
`run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/ext_conf_builder.rb:48:in
`block in build'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/tempfile.rb:291:in
`open'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/ext_conf_builder.rb:30:in
`build'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:169:in
`block in build_extension'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:165:in
`synchronize'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:165:in
`build_extension'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:210:in
`block in build_extensions'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:207:in
`each'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/ext/builder.rb:207:in
`build_extensions'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/installer.rb:844:in
`build_extensions'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/rubygems_gem_installer.rb:72:in
`build_extensions'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/source/rubygems.rb:198:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/gem_installer.rb:54:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:156:in
`do_install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:141:in
`install_serially'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:91:in
`call'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer/parallel_installer.rb:67:in
`call'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:244:in
`install_in_parallel'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:201:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:89:in
`block in run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/process_lock.rb:12:in
`block in lock'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/process_lock.rb:9:in
`open'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/process_lock.rb:9:in
`lock'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:71:in
`run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/installer.rb:23:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli/install.rb:62:in
`run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli.rb:261:in
`block in install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/settings.rb:131:in
`temporary'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli.rb:260:in
`install'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/command.rb:27:in
`run'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in
`invoke_command'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor.rb:392:in
`dispatch'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli.rb:34:in
`dispatch'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/vendor/thor/lib/thor/base.rb:485:in
`start'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/cli.rb:28:in
`start'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/exe/bundle:45:in
`block in <top (required)>'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/lib/bundler/friendly_errors.rb:117:in
`with_friendly_errors'
/home/ec2-user/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/bundler-2.4.12/exe/bundle:33:in
`<top (required)>'
/home/ec2-user/.rbenv/versions/2.7.6/bin/bundle:23:in `load'
/home/ec2-user/.rbenv/versions/2.7.6/bin/bundle:23:in `<main>'
An error occurred while installing mysql2 (0.5.5), and
Bundler cannot continue.
In Gemfile:
mysql2
というエラーが出てしまいました。
自分的に読み解いた感じ、
(Errno::EACCES)
from extconf.rb:118:in `<main>'
と書いてあったので、
ver = `#{mc} --version`.chomp.to_f #extconf.rbの118行目
を確認したのですが、知見が足りず理解できませんでした。
To see why this extension failed to compile, please check the mkmf.log
which can be found here:
/var/www/rails/origin/vendor/bundle/ruby/2.7.0/extensions/x86_64-linux/2.7.0/mysql2-0.5.5/mkmf.log
とも書いてあったので、mkmf.logへ行ってみたのですがどこをみればいいのかわかりませんでした。
ここで質問なのですが
今回はどのようなエラーなのかと解決策をご教授いただきたいです。
Permission denied
が出ているのでアクセス権限周りの問題な可能性があります。(Ruby は rbenv を使っているのに gem がシステムのものを参照して書き込みに失敗している?) / エラーが出るまでに実行したコマンドや、実行環境に関する情報 (各ツールのバージョン等) を追記しておくと回答のヒントになるかもしれません。