LoginSignup
6
9

More than 3 years have passed since last update.

【Rails】Gemのバージョンエラー「Bundler could not find compatible versions for gem」が出てきたときの対処法

Posted at

エラー発生

Railsチュートリアル10章の10.3.2「サンプルのユーザー」で「リスト10.42: GemfileにFaker gemを追加する」で以下のようにgemを追加した。

Gemfile
source 'https://rubygems.org'

gem 'rails',          '5.1.6'
gem 'bcrypt',         '3.1.12'
gem 'faker',          '1.7.3'

そしてbundle installすると、以下のエラーが発生。

Warning: the running version of Bundler (2.0.2) is older than the version that created the lockfile (2.1.0). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "i18n":
  In snapshot (Gemfile.lock):
    i18n (= 1.6.0)

  In Gemfile:
    rails (= 5.1.6) was resolved to 5.1.6, which depends on
      activesupport (= 5.1.6) was resolved to 5.1.6, which depends on
        i18n (>= 0.7, < 2)

    faker (= 1.7.3) was resolved to 1.7.3, which depends on
      i18n (~> 0.5)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

解決方法

調べていたところ、以下の投稿を発見。
https://teratail.com/questions/199869
「Fakerはi18nと依存関係にあります。(Fakerはi18を使って文字列を保存します)

それぞれのGemのバージョンが、良くない組み合わせであったために発生しているエラーかと思われますので、bundle updateをすることで解決するかもです!」

そこでbundle update後、bundle installすると無事インストール成功!

確かにエラー文の最後にもbundle updateをするとコンフリクトが解決するかもと書いてあった...
エラー文もよく読もう。反省。

まとめ

ちなみにbundle updateとは「Gemfile.lockの記述を無視して、GemfileでのGemの指定やそのバージョン指定などに基づいて、gemを更新する。 更新時にGemfile.lockを更新する。」ことだそう。コンフリクトしたらupdateしてみましょう。

参照
https://athomegeek.com/rails_bundleupdate/

6
9
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
6
9