LoginSignup
kuramon01
@kuramon01

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

mysql2のエラーでbundle installできない

解決したいこと

mysql2のエラーを解消して、無事にbundle installしたい。

現在circleCIにビルドする過程で、"rubocop"を導入しようとしているのですが、

bundler: command not found: rubocop
Install missing gem executables with `bundle install`

と出るので、bundle installをすると、以下のエラーが出て途中で止まってしまいます。

発生している問題・エラー

% bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies.....
Using rake 13.0.3
Using concurrent-ruby 1.1.8
Using i18n 1.8.10
Using minitest 5.14.4
Using tzinfo 2.0.4
Using zeitwerk 2.4.2
Using activesupport 6.1.3.2
Using builder 3.2.4
Using erubi 1.10.0
Using mini_portile2 2.5.1
Using racc 1.5.2
Using nokogiri 1.11.3 (arm64-darwin)
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.9.1
Using rails-html-sanitizer 1.3.0
Using actionview 6.1.3.2
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 6.1.3.2
Using nio4r 2.5.7
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.3
Using actioncable 6.1.3.2
Using globalid 0.4.2
Using activejob 6.1.3.2
Using activemodel 6.1.3.2
Using activerecord 6.1.3.2
Using marcel 1.0.1
Using mini_mime 1.0.3
Using activestorage 6.1.3.2
Using mail 2.7.1
Using actionmailbox 6.1.3.2
Using actionmailer 6.1.3.2
Using actiontext 6.1.3.2
Using activemerchant 1.119.0
Using acts_as_list 1.0.4
Using annotate 3.1.1
Using ast 2.4.2
Using execjs 2.7.0
Using autoprefixer-rails 10.2.4.0
Using awesome_nested_set 3.4.0
Using aws-eventstream 1.1.1
Using aws-partitions 1.455.0
・
・
Fetching mysql2 0.5.3
Installing mysql2 0.5.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
・
・
*** 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.
・
・
/Users/〇〇/.rbenv/versions/2.7.3/lib/ruby/2.7.0/mkmf.rb:1050:in
`block in find_library': undefined method `split' for nil:NilClass
(NoMethodError)
from /Users/〇〇/.rbenv/versions/2.7.3/lib/ruby/2.7.0/mkmf.rb:1050:in
`collect'
from /Users/〇〇/.rbenv/versions/2.7.3/lib/ruby/2.7.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:

/Users/〇〇/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/〇〇/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/mysql2-0.5.3
for inspection.
Results logged to
/Users/〇〇/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0/mysql2-0.5.3/gem_make.out

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

In Gemfile:
  mysql2

自分で試したこと

調べていると以下の記事のような解決策がほとんどであったため、実行してみましたが解決することはできませんでした。

% brew install openssl
% bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

% bundle install
再度行うも同じ結果に

同じようなエラーで過去回答( https://teratail.com/questions/314208 )があり、mkmf.logの確認を試みたのですが、よくわからずに詰まっています。

どなたかご教授いただけますと幸いです。

環境

  • MacOS:Monterey(バージョン12.2.1)
  • Ruby 2.7.3p183 使用
  • rbenv versions
    system
    2.7.3
  • 関係あるかわかりませんが、Railsは7を使用しています
0

No Answers yet.

Your answer might help someone💌