bundle installでlistenをインストールする際に起こったエラー

環境

Ruby : -2.2.2
Rails : 4.2.3
DB :MySQL
OS : macOS High Sierra バージョン 10.13.1

起こったエラー

bundle installでlistenをインストールする際に以下のエラーが起こった。

Gem::RuntimeRequirementNotMetError: listen requires Ruby version >= 2.2.3, ~> 2.2. The
current ruby version is 2.2.0.
An error occurred while installing listen (3.1.5), and Bundler cannot continue.
Make sure that `gem install listen -v '3.1.5'` succeeds before bundling.

In Gemfile:
  guard-livereload was resolved to 2.5.2, which depends on
    guard was resolved to 2.14.1, which depends on
      listen

試したこと

・rubyのバージョンを2.2.2に変更
 →すでに2.2.2だったので問題ない。
・ruby、bundlerのバージョンはどこを見にいっているか$ which ruby$ which gemで確認。
  →どちらもrvm下で管理していたので問題なさそう。
・rubyのバージョンによって使えるlistenのバージョンも違うのでlistenのバージョンを下げてから
  $ bundle update
 →よくわからないエラーが吐かれた
   

Bundler could not find compatible versions for gem "capistrano":
In Gemfile:
capistrano (= 3.7.1)
capistrano-bundler was resolved to 1.3.0, which depends on
capistrano (~> 3.1)
capistrano-faster-assets was resolved to 1.1.0, which depends on
capistrano (>= 3.1)
capistrano-rails-console was resolved to 2.2.1, which depends on
capistrano (< 4.0.0, >= 3.5.0)
capistrano-rvm was resolved to 0.1.2, which depends on
capistrano (~> 3.0)
capistrano3-unicorn was resolved to 0.2.1, which depends on
capistrano (>= 3.1.0, ~> 3.1)
Bundler could not find compatible versions for gem "listen":
In Gemfile:
listen (= 1.2)
guard-livereload (~> 2.4) was resolved to 2.5.2, which depends on
guard (~> 2.8) was resolved to 2.12.6, which depends on
listen (~> 2.7)
Bundler could not find compatible versions for gem "nokogiri":
In Gemfile:
nokogiri (= 1.6.8.1)
axlsx (= 1.3.6) was resolved to 1.3.6, which depends on
nokogiri (>= 1.4.1)
capybara (= 2.5.0) was resolved to 2.5.0, which depends on
nokogiri (>= 1.3.3)
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (= 4.2.6)
nested_has_many_through was resolved to 0.0.2, which depends on
rails (>= 3.0.0)
Bundler could not find compatible versions for gem "unicorn":
In Gemfile:
unicorn (= 4.9.0)
unicorn-worker-killer was resolved to 0.4.4, which depends on
unicorn (< 6, >= 4)

・capistranoでエラー出てるっぽい。とりあえずローカル環境で動けばいいのでcapistaranoらへんコメントアウトする。
→また似たようなエラーが...

Bundler could not find compatible versions for gem "listen":
  In Gemfile:
    listen (= 1.2)
    guard-livereload (~> 2.4) was resolved to 2.5.2, which depends on
      guard (~> 2.8) was resolved to 2.12.6, which depends on
        listen (~> 2.7)
Bundler could not find compatible versions for gem "nokogiri":
  In Gemfile:
    nokogiri (= 1.6.8.1)
    axlsx (= 1.3.6) was resolved to 1.3.6, which depends on
      nokogiri (>= 1.4.1)
    capybara (= 2.5.0) was resolved to 2.5.0, which depends on
      nokogiri (>= 1.3.3)
Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails (= 4.2.6)
    nested_has_many_through was resolved to 0.0.2, which depends on
      rails (>= 3.0.0)
Bundler could not find compatible versions for gem "unicorn":
  In Gemfile:
    unicorn (= 4.9.0)
    unicorn-worker-killer was resolved to 0.4.4, which depends on
      unicorn (< 6, >= 4)

・railsらへんは流石にコメントアウトできないのでlistenを消して $ bundle install
 →そしたらmysqlインストールする際にエラー発生。

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

    current directory: /Users/hoge/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.20/ext/mysql2
/Users/hoge/.rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20171115-30954-1fh666c.rb
extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.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.6/5.6.38/lib
-----
creating Makefile

current directory: /Users/hoge/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.20/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/hoge/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.20/ext/mysql2
make "DESTDIR="
compiling infile.c
compiling client.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/Users/haven/.sm/pkg/active/lib'
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/hoge/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.20
for inspection.
Results logged to
/Users/hoge/.rvm/gems/ruby-2.2.2/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/gem_make.out

An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.20'` succeeds before bundling.

In Gemfile:
  mysql2

・出力結果からここが怪しいので以下の文で直接ググる。

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

解決策

調べたらちょうど次のようなサイトRailsプロジェクトでMySQLがbundle installできなかったがあったので、その通りにコマンドを実行。
$ build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

このあと$ bundle installしたら無事に終了した。

結論

・問題を起こしていたlistenをとりあえず削除。
・パスを通してmysqlもインストールできるようにした。

参考サイト

RailsプロジェクトでMySQLがbundle installできなかった

終わりに

これは完全に個人的なエラー解決のメモです。そのため、解決方法としては適切でなかったり、間違ったgemの使い方などをしているかもしれません。
今回のエラーで色々検索してもなかなか解決に至らなかったので自分のために投稿しました。

もし、より良い解決方法などがあればコメントなどでフィードバックをしていただけると幸いです。(エラーを起こした際の情報が少なすぎますが...)

job-error_3

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.