LoginSignup
13
10

More than 3 years have passed since last update.

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

Last updated at Posted at 2019-06-18

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

13
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
10