bundle installで特定のgemがインストールできない
Railsの勉強中、書籍に付属のサンプルプログラムを動かすため、ソースをダウンロードしてbundle install
を実行したら以下のようなエラーが出た。
bundle install
Fetching gem metadata from https://rubygems.org/..........
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.2
...
Fetching rdoc 4.2.0
Downloading rdoc-4.2.0 revealed dependencies not in the API or the lockfile (json (~> 1.4)).
Either installing with `--full-index` or running `bundle update rdoc` should fix the problem.
In Gemfile:
sdoc was resolved to 0.4.1, which depends on
rdoc
どうやらrdoc-4.2.0
というgemのダウンロードでコケている模様。
この状態でbin/rails s
を実行すると、対象のgemが見つからない旨のエラーが出る。
Could not find rdoc-4.2.0 in any of the sources
Run `bundle install` to install missing gems.
かなしい。
対処法
エラーメッセージによると--full-index
かbundle update rdoc
を実行しろとのこと。
Either installing with `--full-index` or running `bundle update rdoc` should fix the problem.
--full-index
はbundle install
のオプションのようだが、説明を見てもよくわからなかった…
Use the rubygems modern index instead of the API endpoint.
Bundler: bundle install
Gemfile.lock
を見てみると対象gemのバージョンが別環境と異なっていたので、問題となっているgemをアップデートすることにした。
bundle update rdoc
bundle update rdoc
を実行するとGemfile.lock
で指定されているrdoc
のバージョンが更新された。
Using rdoc 4.3.0 (was 4.2.0)
以降のgemも無事にインストールされ、bin/rails s
でプログラムの起動が確認できた。
補足
Gemfile.lock
で指定されているgemのバージョンが、RubyGems.orgのリストに存在しない場合にも「Could not find xxx in any of the sources」エラーが発生する模様。
bundle install すると Could not find xxx in any of the sources と怒られる場合の対処法 - Qiita
こちらもgemのupdateで解決するみたい。