解決したいこと
mysql2がインストール出来ないのでインストールしたい
現在rails の環境構築をしているのですが、bundle installをすると以下のようなエラーが出来てきました。
~ Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/mysql2-0.5.3/ext/mysql2 /home/senseiy/.rbenv/versions/3.0.3/bin/ruby -I /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/site_ruby/3.0.0 -r ./siteconf20220307-2102-ko1ye5.rb extconf.rb checking for rb_absint_size()... yes checking for rb_absint_singlebit_p()... yes checking for rb_wait_for_single_fd()... 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-mysqlclientlib --without-mysqlclientlib /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/3.0.0/mkmf.rb:1050:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError) from /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/3.0.0/mkmf.rb:1050:in `collect' from /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/3.0.0/mkmf.rb:1050:in `find_library' from extconf.rb:87:in `<main>' To see why this extension failed to compile, please check the mkmf.log which can be found here: /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.3/mkmf.log ~ Gem files will remain installed in /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/mysql2-0.5.3 for inspection. Results logged to /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.3/gem_make.out /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/site_ruby/3.0.0/rubygems/ext/builder.rb:95:in `run' /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/site_ruby/3.0.0/rubygems/ext/ext_conf_builder.rb:47:in `block in build' /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/3.0.0/tempfile.rb:317:in `open' ~ /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler/worker.rb:54:in `process_queue' /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads' An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue. In Gemfile: mysql2 senseiy@senseIY:~/dictum/dictum$ less /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.3/mkmf.log senseiy@senseIY:~/dictum/dictum$ less /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.3/mkmf.log senseiy@senseIY:~/dictum/dictum$ bundle install Fetching gem metadata from https://rubygems.org/.......... Using rake 13.0.6 Using concurrent-ruby 1.1.9 ~ Using webpacker 4.3.0 Using sass-rails 6.0.0 Using carrierwave-audio 1.0.7 from git@github.com:tanakaworld/carrierwave-audio.git (at master@b0132d6) Using web-console 4.2.0 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/mysql2-0.5.3/ext/mysql2 /home/senseiy/.rbenv/versions/3.0.3/bin/ruby -I /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/site_ruby/3.0.0 -r ./siteconf20220307-2184-5t4wxf.rb extconf.rb checking for rb_absint_size()... yes checking for rb_absint_singlebit_p()... yes checking for rb_wait_for_single_fd()... 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-mysqlclientlib --without-mysqlclientlib /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/3.0.0/mkmf.rb:1050:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError) from /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/3.0.0/mkmf.rb:1050:in `collect' from /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/3.0.0/mkmf.rb:1050:in `find_library' from extconf.rb:87:in `<main>' To see why this extension failed to compile, please check the mkmf.log which can be found here: /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.3/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/mysql2-0.5.3 for inspection. Results logged to /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.3/gem_make.out ~ s/3.0.0/gems/bundler-2.2.33/lib/bundler/worker.rb:54:in `process_queue' /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bundler-2.2.33/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads' An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue. In Gemfile: mysql2
エラー文に
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. To see why this extension failed to compile, please check the mkmf.log which can be found here: /home/senseiy/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/extensions/x86_64-linux/3.0.0/mysql2-0.5.3/mkmf.log extconf failed, exit code 1
と出てきたのでlessコマンドで中身を確認しました。
have_func: checking for rb_absint_size()... -------------------- yes "gcc -o conftest -I/home/senseiy/.rbenv/versions/3.0.3/include/ruby-3.0.0/x86_64-linux -I/home/senseiy/.rbenv/versions/3.0.3/include/ruby-3.0.0/ruby/backward -I/home/senseiy/.rbenv/versions/3.0.3/include/ruby-3.0.0 -I. -I/home/senseiy/.rbenv/versions/3.0.3/include -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -fPIC conftest.c -L. -L/home/senseiy/.rbenv/versions/3.0.3/lib -Wl,-rpath,/home/senseiy/.rbenv/versions/3.0.3/lib -L. -L/home/senseiy/.rbenv/versions/3.0.3/lib -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/senseiy/.rbenv/versions/3.0.3/lib -L/home/senseiy/.rbenv/versions/3.0.3/lib -lruby -lm -lc" checked program was: /* begin */ 1: #include "ruby.h" 2: 3: int main(int argc, char **argv) 4: { 5: return !!argv[argc]; 6: } /* end */ "gcc -o conftest -I/home/senseiy/.rbenv/versions/3.0.3/include/ruby-3.0.0/x86_64-linux -I/home/senseiy/.rbenv/versions/3.0.3/include/ruby-3.0.0/ruby/backward -I/home/senseiy/.rbenv/versions/3.0.3/include/ruby-3.0.0 -I. -I/home/senseiy/.rbenv/versions/3.0.3/include -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -fPIC conftest.c -L. -L/home/senseiy/.rbenv/versions/3.0.3/lib -Wl,-rpath,/home/senseiy/.rbenv/versions/3.0.3/lib -L. -L/home/senseiy/.rbenv/versions/3.0.3/lib -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/senseiy/.rbenv/versions/3.0.3/lib -L/home/senseiy/.rbenv/versions/3.0.3/lib -lruby -lm -lc" checked program was: /* begin */ 1: #include "ruby.h" 2: 3: /*top*/ 4: extern int t(void); 5: int main(int argc, char **argv) 6: { 7: if (argc > 1000000) { 8: int (* volatile tp)(void)=(int (*)(void))&t; 9: printf("%d", (*tp)()); 10: } 11: 12: return !!argv[argc]; 13: } 14: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_absint_size; return !p; } /* end */ -------------------- have_func: checking for rb_absint_singlebit_p()... -------------------- yes
ですが、このファイルを見ても何をすればいいか分かりません。
https://teratail.com/questions/314208
この方と同じエラーだと思います。この方の場合はログをみて解決出来たようですが、どこにインストールすべきファイルが書いてあるのか分かりません。何かしらアドバイスがあればよろしくお願いいたします。
その他
・wsl2のubuntuを使っています
・rubyのバージョンは3.0.3です
・mysqlは
https://takake-blog.com/wsl2-ubuntu2004-mysql/
この方の記事を参考にインストールしました。
・railsのバージョンを確認しても、Could not find mysql2-0.5.3 in any of the sources
Run bundle install
to install missing gems.と出てきます。ですが、bundle installは失敗してしまいます。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。