Help us understand the problem. What is going on with this article?

mysql2インストールにはまった

gemfilegem 'mysql2', '~> 0.3.21’をかいて

bundle installしたときにこんなエラーが出る

Fetching mysql2 0.3.21 (was 0.5.2)
Installing mysql2 0.3.21 (was 0.5.2) with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/nosappu/.rbenv/gems/2.5.0/gems/mysql2-0.3.21/ext/mysql2
/Users/nosappu/.rbenv/versions/2.5.1/bin/ruby -I /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0 -r
./siteconf20190618-18677-1n2dmi9.rb extconf.rb --with-ldflags\=-L/usr/local/opt/openssl/lib\ --with-cppflags\=-I/usr/local/opt/openssl/include
checking for ruby/thread.h... *** 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=/Users/nosappu/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
/Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:590:in `try_cpp'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:1097:in `block in have_header'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:947:in `block in checking_for'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:350:in `block (2 levels) in postpone'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:320:in `open'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:350:in `block in postpone'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:320:in `open'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:346:in `postpone'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:946:in `checking_for'
    from /Users/nosappu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/mkmf.rb:1096:in `have_header'
    from extconf.rb:15:in `<main>'

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

  /Users/nosappu/.rbenv/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/mysql2-0.3.21/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/nosappu/.rbenv/gems/2.5.0/gems/mysql2-0.3.21 for inspection.
Results logged to /Users/nosappu/.rbenv/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/mysql2-0.3.21/gem_make.out

gem_make.outもmfmk.fileものログみてもなんだかわからん…

場所
/Users/nosappu/.rbenv/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/mysql2-0.3.21

この記事を発見
エラーの落ちているところが同じだったので読み進めていくと

brew install mysql

gem install mysql2 -v '0.3.21' -- --srcdir=/usr/local/mysql/include

bundle install

この三つのコマンドを実行しろ。と

この場所に/usr/local/Cellarにはmysqlがはいっていたので、二行目、三行目のコマンドを実行し、無事mysql2を入れることができた!!

別日は↑でできなかった

bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include"

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

を打つことで解決

参考: https://qiita.com/tktcorporation/items/0ef8c930fc18ce72c301

// 余談

pumaをインストールできない時は

bundle config build.puma --with-cflags="-Wno-error=implicit-function-declaration"

参考

bundle installを見よう

checking for clang... yes
checking for Magick-config... no
checking for pkg-config... yes

おっ magick configが落ちてる!

$ brew install imagemagick@6
$ brew install pkg-config
$ export PKG_CONFIG_PATH=/usr/local/opt/imagemagick@6/lib/pkgconfig
$ gem install rmagick

これでオッケー
https://qiita.com/niwasawa/items/1144f20a9f2de4b76977

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした