Help us understand the problem. What is going on with this article?


More than 1 year has passed since last update.

Rails アプリの Heroku デプロイでハマったので解決法を残しておく。


Bundler 2.0.1 を入れ直し、Gemfile.lock を再生成し、commit & push heroku。
Gemfile.lock に BUNDLED WITH 2.0.2 と書かれているとダメっぽい。


  • macOS Mojave 10.14.5
  • Ruby 2.6.3
  • Bundler 2.0.2
  • Rails 5.1.6


$ git push heroku master


 !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
            Detected buildpacks: Ruby,Node.js
-----> Ruby app detected
-----> Compiling Ruby/Rails
 !     There was an error parsing your Gemfile, we cannot continue
 !     /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/vendor/ruby/heroku-18/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
 !     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/vendor/ruby/heroku-18/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
 !     from /tmp/d20190615-117-1464bpn/bundler-2.0.1/bin/bundle:23:in `<main>'
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

Bundler に問題がありそうなので、Heroku の Ruby Buildpack での Bundler の扱いを調べた。

Heroku Ruby Support | Heroku Dev Center

The following libraries are used by the platform for managing and running Ruby applications and cannot be specified. For application dependency resolution and management, bundler is installed based on the contents of your Gemfile.lock. If you have a BUNDLED WITH in your Gemfile.lock then you will receive a different version of Bundler:

  • Applications specifying Bundler 2.x in their Gemfile.lock will receive bundler: 2.0.1
  • Applications specifying Bundler 1.x in their Gemfile.lock will receive bundler: 1.15.2
  • Applications with no BUNDLED WITH in their Gemfile.lock will default to bundler: 1.15.2

どうやら、Gemfile.lock 内の BUNDLED WITH に書かれた Bundler のバージョンによって Heroku で使われる Bundler のバージョンが決まるらしい。

ローカルの Bundler のバージョンは 2.0.2。

$ bundle -v
Bundler version 2.0.2

そして Gemfile.lock を見ると末尾に以下の記述がある。


この場合、2.x の指定なので、Heroku では Bundler 2.0.1 が使われて特に問題無さそうだが、2.0.1 と 2.0.2 の違いがデプロイ失敗の原因かも知れない。


Bundler 2.0.1 に入れ替え、Gemfile.lock を再生成してみる。

$ gem uninstall bundler

Remove executables:

in addition to the gem? [Yn]  Y
Removing bundler
Successfully uninstalled bundler-2.0.2
$ gem install bundler -v 2.0.1
$ bundle -v  # Bundler version 2.0.1
$ cd [project directory]
$ rm Gemfile.lock
$ bundle --without production

差分は BUNDLED WITH の部分だけ。

$ git diff

diff --git a/Gemfile.lock b/Gemfile.lock
index c2077c0..e3287c7 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -180,4 +180,4 @@ DEPENDENCIES
   web-console (= 3.5.1)

-   2.0.2
+   2.0.1
$ git commit -am 'Change Bundler ver. (2.0.2 -> 2.0.1)'
$ git push heroku master


Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away