bundle installをするとbundle updateをするように言われる

背景

Rails newで新しくWebアプリケーションを作成した後、Gemfileを更新し、bundle instal --without productionlをすると、

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

というエラーがRails Tutorialのサンプルアプリケーションに取り組み度、毎回出現する。

原因は、

You have requested:
  spring = 2.0.2

The bundle currently has spring locked at 2.1.0.
Try running `bundle update spring`

という事で、springのバージョンが違う事に起因するようだ。

bundle update spring

をすると、

You have requested:
  minitest = 5.10.3

The bundle currently has minitest locked at 5.13.0.
Try running `bundle update minitest`

と、今度はminitestのバージョンが違うらしい。

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

と、親切に複数のgemが関連した場合はbundle updateを実行してみてと教えてくれているので、その通りに実行する。

そうすると、Gemfileに記載した通りのgemとバージョンが正しくインストールされ、目的のbundle install --without productionも実行できた。

技術的に学べたこと

  • Bundler
    • Rubyアプリケーションのgemを管理する為のgem
  • Gemfile
    • gemをインストールする為の設計図
  • gemfile.lock
    • インストールしたgemの結果
  • bundle updatebundle installの違い
    • bundle updateは、Gemfileを元にgemのインストールを行い、その後gemfile.lockを更新する
    • bundle installは、gemfile.lockを元にgemのインストールを行う。gemfile.lockに何も記述されていない、かつGemfileに記述がある場合は、そのgemと関連するgemを自動でインストールした後に、gemfile.lockを更新する