問題
- Rails Tutorial (5.1) 第1章 1.3.1
-
bundle install
しようとすると以下のようなエラーが出る
Fetching gem metadata from https://rubygems.org/............
You have requested:
spring = 2.0.2
The bundle currently has spring locked at 2.1.1.
Try running `bundle update spring`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
- 書いてあるとおりに
bundle update spring
をしてもまたエラー
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Bundler could not find compatible versions for gem "activesupport":
In snapshot (Gemfile.lock):
activesupport (= 5.1.7)
In Gemfile:
rails (= 5.1.6) was resolved to 5.1.6, which depends on
activesupport (= 5.1.6)
coffee-rails (= 4.2.2) was resolved to 4.2.2, which depends on
railties (>= 4.0.0) was resolved to 5.1.7, which depends on
activesupport (= 5.1.7)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
- さらに
bundle update
してもエラー- この手順で直る場合もあるみたい
Bundler could not find compatible versions for gem "actionpack":
In snapshot (Gemfile.lock):
actionpack (>= 5.1.7)
In Gemfile:
rails (= 5.1.6) was resolved to 5.1.6, which depends on
actionpack (= 5.1.6)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
原因
- おそらくプロジェクト作成時にインストールしたGemよりも前のバージョンをインストールしようとしたのが原因
- そのプロジェクト作成時の情報が
Gemfile.lock
に保存されていて、依存関係の影響でうまくいってないのかも
解決法
-
Gemfile.lock
を削除して、bundle install
を行う
$ rm Gemfile.lock
$ bundle install
対策
- 自分でGemfileを編集するときは、RubyGems.orgでGemを検索し、詳細ページの「GEMFILE」をそのままコピーする