11
5

More than 3 years have passed since last update.

(rails sエラー)digest/md5.bundle

Last updated at Posted at 2020-01-02

あけましておめでとうございます!
みなさまにとって最高の一年になることを願っています!

さて私は年明け早々エラーと遭遇しました
もうすぐphpを使った仕事を開始するので、laravelの環境構築をした際、久しぶりにrailsで作成したアプリをrails sでサーバーを立ち上げようとしたところ、エラーになったのでメモしておこうと思います!

OSはmacです

エラー内容

$ rails s
18: from bin/rails:3:in `<main>'
17: from bin/rails:3:in `load'
(省略)
/Users/ユーザーの名前/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': dlopen(/Users/ユーザーの名前/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/digest/md5.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /Users/ユーザーの名前/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/digest/md5.bundle
Reason: image not found - /Users/ユーザーの名前/.rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-darwin18/digest/md5.bundle

やっぱlaravelの環境構築したあとのエラーなので、その過程で何かおかしくなったなと感じ、いろいろググりました。そしたらteratailで全く同じエラーに悩む方の投稿を発見

この回答でのエラーの原因の見解は、

  • 以前rbenv/ruby-buildを用いてインストールした2.5.1がある
  • Homebrewでパッケージをアップグレードしたことにより、OpenSSLのバージョンが上がった
  • rubyが参照していたバージョンのOpenSSLがなくなったことにより、エラー発生

この内容全く同じだ!

ということで、rubyを再インストールすることでエラーが解消すると記載されていたため再インストールを試みることに

といってもrubyの再インストールでどうやるの?と思いまたググる
で、これらの記事を参考にさせていただきました

https://qiita.com/pugiemonn/items/88b476dcf5d651ae5397
https://qiita.com/Okame-chan/items/39052dc4d4c3cebfb1ee
https://qiita.com/MasanoriIwakura/items/9f902c7e21fbbf8b18e9
たぶん他にも参考にした記事がありますがググりすぎてよく覚えてません・・・

rubyのバージョンを確認

まずインストールされているrubyのバージョンを確認します

$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]

私のrubyのバージョンはruby 2.5.1です

rubyの保存場所を確認

$ which ruby
/Users/ユーザーの名前/.rbenv/shims/ruby

.rbenvにあることを確認

インストール可能なrubyのバージョンを確認

$ rbenv install -l
1.8.5-p52
1.8.5-p113
1.8.5-p114
1.8.5-p115
1.8.5-p231
1.8.6
1.8.6-p36
1.8.6-p110
(省略)

私のもともと入っていたrubyのバージョンよりも最新のバージョンがありましたが、バージョンアップすることによる予期せぬエラーを恐れ、2.5.1を再インストールすることにしました

rubyを再インストール

参考にさせていただいた記事は一度rubyをアンインストールするよう記載されていたのですが、アンインストールって怖ぇて思ってアンインストールのコマンドを一旦無視してやってみることに

$ rbenv install 2.5.1
rbenv: /Users/ユーザーの名前/.rbenv/versions/2.5.1 already exists
continue with installation? (y/N) y

ここで一旦y/Nを求められたのでyを入力

Downloading openssl-1.1.1d.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/1e3a91bc1f9dfce01af26026f856e064eab4c8ee0a8f457b5ae30b40b8b711f2
Installing openssl-1.1.1d...
Installed openssl-1.1.1d to /Users/ユーザーの名前/.rbenv/versions/2.5.1

Downloading ruby-2.5.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.bz2
Installing ruby-2.5.1...
ruby-build: using readline from homebrew
Installed ruby-2.5.1 to /Users/ユーザーの名前/.rbenv/versions/2.5.1

ユーザーの名前noMacBook-Pro:~ ユーザーの名前$ cd my_app/
ユーザーの名前noMacBook-Pro:my_app ユーザーの名前$ cd wakuwakustory
ユーザーの名前noMacBook-Pro:wakuwakustory ユーザーの名前$ rails s
Ignoring nokogiri-1.10.7 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.7
Ignoring nokogiri-1.10.5 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.5
Ignoring nokogiri-1.10.4 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.4

(省略)

Could not find nokogiri-1.10.5 in any of the sources
Run `bundle install` to install missing gems.

きました、忌々しきgem 'nokogiri'
で、なんかbundle installするよう促されたのでやってみる

bundle install

$ bundle install
Ignoring bcrypt-3.1.13 because its extensions are not built. Try: gem pristine bcrypt --version 3.1.13
Ignoring bindex-0.8.1 because its extensions are not built. Try: gem pristine bindex --version 0.8.1
Ignoring bindex-0.7.0 because its extensions are not built. Try: gem pristine bindex --version 0.7.0
(省略)
Fetching mysql2 0.5.2
Installing mysql2 0.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
(省略)
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.

いっぱいログが出てきて、今度はmysql2がでエラーが発生
エラー文をgoogle翻訳様に翻訳していただいたところ

mysql2(0.5.2)のインストール中にエラーが発生し、Bundlerを続行できません。
バンドルする前に、「gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'」が成功することを確認してください。

とのこと

mysqlをインストールする

試しに

$ gem install mysql2 -v '0.5.2'
Ignoring bindex-0.7.0 because its extensions are not built. Try: gem pristine bindex --version 0.7.0
Ignoring binding_of_caller-0.8.0 because its extensions are not built. Try: gem pristine binding_of_caller --version 0.8.0
(省略)
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.
(省略)

よくわからなくなってきました
とりあえずうまくいってません

で、ググったところ同じようなエラー解決の記事を発見

こちらに2つコマンド

$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
$ bundle install --path=vendor/bundle

が紹介されていたのでやってみる
まず一つ目

$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
You are replacing the current local value of build.mysql2, which is currently nil

よくわからんが失敗
もう一つのコマンドを実行してみる

$ bundle install --path=vendor/bundle
Ignoring bindex-0.7.0 because its extensions are not built. Try: gem pristine bindex --version 0.7.0
Ignoring binding_of_caller-0.8.0 because its extensions are not built. Try: gem pristine binding_of_caller --version 0.8.0
(省略)

  +--------------------------------------------------------------------+
  |                                                                    |
  |  NOTICE: chromedriver-helper is deprecated after 2019-03-31.       |
  |                                                                    |
  |  Please update to use the 'webdrivers' gem instead.                |
  |  See https://github.com/flavorjones/chromedriver-helper/issues/83  |
  |                                                                    |
  +--------------------------------------------------------------------+

Post-install message from sass:

Ruby Sass has reached end-of-life and should no longer be used.

* If you use Sass as a command-line tool, we recommend using Dart Sass, the new
  primary implementation: https://sass-lang.com/install

* If you use Sass as a plug-in for a Ruby web framework, we recommend using the
  sassc gem: https://github.com/sass/sassc-ruby#readme

* For more details, please refer to the Sass blog:
  https://sass-lang.com/blog/posts/7828841

こんな感じで終了した
なんかsassについて言っているがエラーではなさそうなのでここでは無視することに

bundle install

ここでひとまずbundle installしてみる

$ bundle install
(省略)
Bundle complete! 45 Gemfile dependencies, 138 gems now installed.
Bundled gems are installed into `./vendor/bundle`

成功!

rails s

rails sコマンドを実行したところ成功しました!・・・が・・・

大量のgem pristine

サーバーの起動には成功したもののrails sコマンド後のログを見ると

Ignoring nokogiri-1.10.7 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.7
Ignoring nokogiri-1.10.4 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.4
Ignoring nokogiri-1.10.3 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.3
(省略)
(上の3つのログは100行ぐらいループして表示されてました)
Ignoring bindex-0.7.0 because its extensions are not built. Try: gem pristine bindex --version 0.7.0
Ignoring binding_of_caller-0.8.0 because its extensions are not built. Try: gem pristine binding_of_caller --version 0.8.0
Ignoring bootsnap-1.4.4 because its extensions are not built. Try: gem pristine bootsnap --version 1.4.4

=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.5.1-p57), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000

こんな感じで今までみたことないログが大量に吐かれ、忌々しき'nokogiri'は大量に吐き出てきました

もしnokogiriが人であれば今すぐ自宅に行ってロンダートからのフライエルボーを食らわしたい気持ちを抑えてとりあえず書かれているとおりtryしてみることに

$ gem pristine nokogiri --version 1.10.7
$ gem pristine nokogiri --version 1.10.4
$ gem pristine nokogiri --version 1.10.3
$ gem pristine bindex --version 0.7.0
$ gem pristine binding_of_caller --version 0.8.0
$ gem pristine bootsnap --version 1.4.4

順々に実行していき、もう一度rails sしてみる

$ rails s
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.5.1-p57), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000

できた!
rails,laravelどちらの挙動も確認しましたが、とりあえずローカル環境は大丈夫でした。
よかったよかった

ちなみに

この設定をrailsのアプリケーションフォルダで実行していたからなのかわからないが、githubレポジトリの変更箇所が9000個溜まってました・・
なにこれ・・
デプロイできるのかな・・

まだ試してないですが、多分いろいろと問題が出てきそうなのでもし、問題が起きて「解決できた!」ときはまた記事にします・・

追記

デプロイしてみました
というても、変更のあったレポジトリはコミットしたところ、エラー文が表示されコミットできませんでした。
私は以前通っていたスクールの方針で「githubデスクトップ」というアプリケーションを利用してgithubの操作をしているのですが、そこで
内容は「長すぎてコミットできません!」
みたいな内容のエラーが吐かれました。

で、仕方なくmasterに戻ったらなぜか120個くらい変更ファイルがあって、試しにコミットしたところできました。
それで9000個変更のあったレポジトリは放置してデプロイを試したところ、できました。

が、そのあとまたmasterに先ほどの9000個の変更がなぜか降りてきてしまいました。
今の所デプロイ先でもうまく動いてくれてるので、一旦無視する方向にしました・・(^◇^;)

で、せっかくなので私が練習で作ったアプリを最後ご紹介して終わろうと思います

https://wakuwakustory.com
(2021/01/08追記:s3の設定を別のアプリに設定したので画像の投稿はできません!すいません!)
(2021/05/21追記:閉鎖しました。ご覧になってくれた方はありがとうございました!)

多分問題なく動くはずなのでいじって適当に遊んでいただければありがたく感じます!
(並び替えの機能が少しおかしいです・・)
ということでおそらくrailsやrubyについての投稿はしばらくやらなくなると思いますが、今後もよろしくお願いします!

11
5
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
11
5