Programming from 30

自分の備忘録が、誰かの為になれば・・

【Ruby】bundle install と bundle updateの際に出るエラー解消!!

なぜかわからないけど、以下のエラーが出るようになりました😅インストールはできているけど、いつか大きなバグに繋がるので解決しておきました!

$ bundle install 
Ignoring bindex-0.5.0 because its extensions are not built.  Try: gem pristine bindex --version 0.5.0
Ignoring byebug-10.0.0 because its extensions are not built.  Try: gem pristine byebug --version 10.0.0
Ignoring byebug-9.0.6 because its extensions are not built.  Try: gem pristine byebug --version 9.0.6
Ignoring ffi-1.9.23 because its extensions are not built.  Try: gem pristine ffi --version 1.9.23
Ignoring nio4r-2.2.0 because its extensions are not built.  Try: gem pristine nio4r --version 2.2.0
Ignoring nokogiri-1.8.2 because its extensions are not built.  Try: gem pristine nokogiri --version 1.8.2
Ignoring puma-3.11.3 because its extensions are not built.  Try: gem pristine puma --version 3.11.3
Ignoring puma-3.9.1 because its extensions are not built.  Try: gem pristine puma --version 3.9.1
Ignoring sqlite3-1.3.13 because its extensions are not built.  Try: gem pristine sqlite3 --version 1.3.13
Ignoring websocket-driver-0.6.5 because its extensions are not built.  Try: gem pristine websocket-driver --version 0.6.5
(省略)
Using rails 5.2.1
Using tilt 2.0.8
Using sinatra 2.0.4
Bundle complete! 3 Gemfile dependencies, 49 gems now installed.
Bundled gems are installed into `./vendor/bundle`

上記のエラーで検索をかけると結構同じ症状に悩まされる方が多いようです。

Ignoring gems because its extensions are not built [duplicate]

rails test で nokogiri のエラーが発生するときの対処

ruby関係のコマンドを入力すると常にエラー?警告?が出る

他にも多数解決策が挙げられているが、私の症状を解消するものはなく、メンターの駒形さんに相談!「rbenvrubyの再インストール。ダメならクリーンインストール!」というアドバイスを頂き実行!

まずはrbenvruby_buildの入っている~/.rbenvを削除

rm -rf ~/.rbenv

次にrbenvruby_buildの再インストール

# rbenvをgitからクローン
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
# rbenvげのパスの設定
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
exec $SHELL -l
# rbenvが入っているか確認
rbenv --version
# ruby_buildのインストール
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# rubyのインストールするリストを確認
rbenv install --list 2.5.1をインストール
rbenv install 2.5.1
# rubyのバージョン確認
ruby -v
# 2.5.1を使用する
rbenv global 2.5.1
# rbenvのrubyを使っているか確認
which ruby -> ok!!!

bundlerもインストール

gem install bundler
# 確認
bundler -v
# ~/.rbenv/versions/2.x.y/bin/ 以下に置いてあるコマンド群を ~/.rbenv/shims/以下に置いて使えるようにする

rbenv rehash

#インストールパスを指定
 bundle install --path vendor/bundle

最後のコマンドを叩くと再度エラー発生

Retrying fetcher due to error (2/4): Bundler::Fetcher::CertificateFailureError Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about OpenSSL certificates, see http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'.
Retrying fetcher due to error (3/4): Bundler::Fetcher::CertificateFailureError Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about OpenSSL certificates, see http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'.
Retrying fetcher due to error (4/4): Bundler::Fetcher::CertificateFailureError Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about OpenSSL certificates, see http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'.
Could not verify the SSL certificate for https://rubygems.org/.
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information
about OpenSSL certificates, see http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'

このエラーはbundle installの実行時にhttps:// rubygems.org/.に対してhttps接続したんだけど、SSL証明書がきちんと確認できてませんよというときに発生する。このときに確認した手順としては、 1,OpenSSLがきちんと入っているか? 2,証明書が有効なものになっているのか? の二点。詳しい手順は以下に記載します。

参考:rails の bundle install が 「Could not verify the SSL certificate for https://rubygems.org/.」で失敗するとき こちらの方に助けて頂きました!

その後bundle install --path vendor/bundleを叩く!

Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Fetching rake 12.3.1
Installing rake 12.3.1
(中略)
Bundle complete! 3 Gemfile dependencies, 49 gems now installed.
Bundled gems are installed into `./vendor/bundle`
Post-install message from yard:
--------------------------------------------------------------------------------
As of YARD v0.9.2:

RubyGems "--document=yri,yard" hooks are now supported. You can auto-configure
YARD to automatically build the yri index for installed gems by typing:

    $ yard config --gem-install-yri

See `yard config --help` for more information on RubyGems install hooks.

You can also add the following to your .gemspec to have YARD document your gem
on install:

    spec.metadata["yard.run"] = "yri" # use "yard" to build full HTML docs.

--------------------------------------------------------------------------------

できました!

結構ここまで来るのにかなり時間を費やしてしまいました!最後の選択肢のクリーンインストールまでいかなくて良かったです。原因としてはOS Mojaveをインストールした事からの権限異常の確率が高いそう。OSインストールのタイミングは考えたいものです。
今後は関連していそうなものを再インストールを選択肢としていきます!駒形さんには毎度感謝しかございません!ありがとうございます!