[Heroku][Rails] Gemfile を編集したら必ず bundle install をする

Heroku + Rails で開発をしてて、不要な gem を Gemfile から削除したら、必ず bundle install をしましょう。

Heroku

Gemfile を編集するときの手順は以下の通りです。

1. Gemfileにgemを追加する(または、不要なgemを削除する)

2. bundle install

3. git add, git commit

4. git push heroku master

bundle install しないと Gemfile.lock ファイルの内容が変更されないので、git push しても下記のようなエラーが出てしまいます。

$ git push heroku master
Counting objects: 17, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 714 bytes, done.
Total 9 (delta 7), reused 0 (delta 0)
 
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.rc
       Running: bundle install --without development:test --path vendor/bundle --deployment
       You are trying to install in deployment mode after changing
       your Gemfile. Run `bundle install` elsewhere and add the
       updated Gemfile.lock to version control.
       You have deleted from the Gemfile:
       * bootstrap-sass (= 1.4.0)
 !
 !     Failed to install gems via Bundler.
 !
 !     Heroku push rejected, failed to compile Ruby/rails app
 
To [email protected]:xxxxxx.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:xxxxxx.git'

以上、Gemfile を編集したら必ず bundle install をするように心掛けたい、現場からお送りしました。

参考情報