またbundle installがmysqlでこけた

ちょっと期間があくとbundle installした際にmysql gemが入らなくなることがしばしばあります。

今回はopensslのバージョンが古いようでインストールに失敗しておりました。

無事bundle installできるまでの手順を書いておこうと思います。

 

エラー内容

bundle installしたら以下のエラーとなるました。

$ bundle install

Fetching mysql2 0.5.2

Installing mysql2 0.5.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

 

current directory:

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/ext/mysql2

/Users/hayashiyoshino/.rbenv/versions/2.6.1/bin/ruby -I

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/site_ruby/2.6.0 -r

./siteconf20191104-88481-11ysrdb.rb extconf.rb

--with-ldflags=-L/usr/local/opt/openssl/lib

--with-cppflags=-I/usr/local/opt/openssl/include

checking for rb_absint_size()... *** 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/hayashiyoshino/.rbenv/versions/2.6.1/bin/$(RUBY_BASE_NAME)

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:467:in

`try_do': The compiler failed to generate an executable file. (RuntimeError)

You have to install development tools first.

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:552:in

`try_link0'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:570:in

`try_link'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:782:in

`try_func'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:1069:in

`block in have_func'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:959:in

`block in checking_for'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:361:in

`block (2 levels) in postpone'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:331:in

`open'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:361:in

`block in postpone'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:331:in

`open'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:357:in

`postpone'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:958:in

`checking_for'

from

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/2.6.0/mkmf.rb:1068:in

`have_func'

from extconf.rb:25:in `<main>'

 

To see why this extension failed to compile, please check the mkmf.log which

can be found here:

 

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/mkmf.log

 

extconf failed, exit code 1

 

Gem files will remain installed in

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2

for inspection.

Results logged to

/Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out

 

An error occurred while installing mysql2 (0.5.2), and Bundler

cannot continue.

Make sure that `gem install mysql2 -v '0.5.2' --source

'https://rubygems.org/'` succeeds before bundling.

 

In Gemfile:

  mysql2 

 

エラー文通り素直にgem install mysql2を実行しても失敗します。

gem install mysql2するだけですぐ治る事滅多にないのでやっぱり…という気持ちになりますw

$ gem install mysql2

Building native extensions. This could take a while...

ERROR:  Error installing mysql2:

ERROR: Failed to build gem native extension.

 

    current directory: /Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/ext/mysql2

/Users/hayashiyoshino/.rbenv/versions/2.6.1/bin/ruby -I /Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/site_ruby/2.6.0 -r ./siteconf20191104-88888-diygu6.rb extconf.rb

checking for rb_absint_size()... yes

checking for rb_absint_singlebit_p()... yes

checking for rb_wait_for_single_fd()... yes

-----

Using mysql_config at /usr/local/bin/mysql_config

-----

checking for mysql.h... yes

checking for errmsg.h... yes

checking for SSL_MODE_DISABLED in mysql.h... yes

checking for SSL_MODE_PREFERRED in mysql.h... yes

checking for SSL_MODE_REQUIRED in mysql.h... yes

checking for SSL_MODE_VERIFY_CA in mysql.h... yes

checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes

checking for MYSQL.net.vio in mysql.h... yes

checking for MYSQL.net.pvio in mysql.h... no

checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes

checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes

checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes

checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes

checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes

checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes

checking for my_bool in mysql.h... yes

-----

Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load

-----

-----

Setting libpath to /usr/local/Cellar/mysql/5.7.21/lib

-----

creating Makefile

 

current directory: /Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/ext/mysql2

make "DESTDIR=" clean

 

current directory: /Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/ext/mysql2

make "DESTDIR="

compiling client.c

compiling infile.c

compiling mysql2_ext.c

compiling result.c

compiling statement.c

linking shared-object mysql2/mysql2.bundle

ld: library not found for -lssl

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [mysql2.bundle] Error 1

 

make failed, exit code 2

 

Gem files will remain installed in /Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2 for inspection.

Results logged to /Users/hayashiyoshino/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out

 

 

解決方法

brew outdatedコマンドで確認してみたところ、openssl のバージョンが古いようでした。

$ brew outdated

bison (3.3.2) < 3.4.2

git (2.17.0) < 2.23.0_1

imagemagick (7.0.7-32) < 7.0.8-66

jq (1.5_3) < 1.6

mysql (5.7.21) < 8.0.17_1

mysql@5.6 (5.6.39) < 5.6.43

node (12.10.0) < 12.11.1

oniguruma (6.8.2) < 6.9.3

openssl (1.0.2q) < 1.0.2t

rbenv (1.1.1) < 1.1.2

redis (5.0.4) < 5.0.6

ruby-build (20180329, 20181019, 20181225, 20190130) < 20191004

telnet (54.50.1) < 60

 

そのためbrewを使ってopenssl をアップデートします。

$ brew upgrade openssl

 

Error: Permission denied @ apply2files - /usr/local/bin/archive/clusterdb

 

パーミッションがないと言われたので/usr/localのパーミッションを変更しもう一度アップデートします。

 

$ sudo chown -R $user /usr/local

Password:

usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ...

       chown [-fhv] [-R [-H | -L | -P]] :group file ...

 

その後gem install mysql2をし直します。

$  gem install mysql2-v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

Building native extensions with: '--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include'

This could take a while...

Successfully installed mysql2-0.5.2

Parsing documentation for mysql2-0.5.2

Installing ri documentation for mysql2-0.5.2

Done installing documentation for mysql2 after 0 seconds

1 gem installed

 

これで無事bundle installできるようになりました!

$ bundle install

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.

Fetching gem metadata from https://rubygems.org/............

Fetching gem metadata from https://rubygems.org/.

Resolving dependencies....

Using rake 13.0.0

Using concurrent-ruby 1.1.5

Using i18n 1.7.0

Using minitest 5.13.0

Using thread_safe 0.3.6

Using tzinfo 1.2.5

Using activesupport 5.2.3

Using builder 3.2.3

Using erubi 1.9.0

Using mini_portile2 2.4.0

Using nokogiri 1.10.5

Using rails-dom-testing 2.0.3

Using crass 1.0.5

Using loofah 2.3.1

Using rails-html-sanitizer 1.3.0

Using actionview 5.2.3

Using rack 2.0.7

Using rack-test 1.1.0

Using actionpack 5.2.3

Using nio4r 2.5.2

Using websocket-extensions 0.1.4

Using websocket-driver 0.7.1

Using actioncable 5.2.3

Using globalid 0.4.2

Using activejob 5.2.3

Using mini_mime 1.0.2

Using mail 2.7.1

Using actionmailer 5.2.3

Using activemodel 5.2.3

Using arel 9.0.0

Using activerecord 5.2.3

Using mimemagic 0.3.3

Using marcel 0.3.3

Using activestorage 5.2.3

Using public_suffix 4.0.1

Using addressable 2.7.0

Using io-like 0.3.0

Using archive-zip 0.12.0

Using bindex 0.8.1

Using msgpack 1.3.1

Using bootsnap 1.4.5

Using bundler 2.0.1

Using byebug 11.0.1

Using regexp_parser 1.6.0

Using xpath 3.2.0

Using capybara 3.29.0

Using childprocess 3.0.0

Using chromedriver-helper 2.1.1

Using coffee-script-source 1.12.2

Using execjs 2.7.0

Using coffee-script 2.4.1

Using method_source 0.9.2

Using thor 0.20.3

Using railties 5.2.3

Using coffee-rails 4.2.2

Using ffi 1.11.1

Using jbuilder 2.9.1

Using rb-fsevent 0.10.3

Using rb-inotify 0.10.0

Using ruby_dep 1.5.0

Using listen 3.1.5

Using mysql2 0.5.2

Using puma 3.12.1

Using sprockets 3.7.2

Using sprockets-rails 3.2.1

Using rails 5.2.3

Fetching rubyzip 2.0.0

Installing rubyzip 2.0.0

Using sass-listen 4.0.0

Using sass 3.7.4

Using tilt 2.0.10

Using sass-rails 5.1.0

Fetching selenium-webdriver 3.142.6

Installing selenium-webdriver 3.142.6

Using spring 2.1.0

Using spring-watcher-listen 2.0.1

Using turbolinks-source 5.2.0

Using turbolinks 5.2.1

Using uglifier 4.2.0

Using web-console 3.7.0

Bundle complete! 18 Gemfile dependencies, 78 gems now installed.

Use `bundle info [gemname]` to see where a bundled gem is installed.

 

 

感想その他

MySQLしかり、ポスグレしかり、db系のgemは定期的にインストール出来なくなりますw

エラー文は同じでも、以前と同じ方法で解決できない事が多いのでややこいです。