LoginSignup
23
16

More than 3 years have passed since last update.

Herokuにpushしようとしたら「 Failed to install gems via Bundler.」というエラーが出た

Last updated at Posted at 2021-03-10

考えられる原因

調べたところ主な原因としては以下のものがあるっぽい

  • bundle install をし忘れている
  • gemのsplite3が本番環境で適用されている
  • Herokuとローカルの bundler のバージョンが異なる

対応

bundle installをし忘れていた時

単純に bundle install すればいい

$ bundle install --without production
$ git commit -a -m "Update gemfile.lock for heroku"
$ git push heroku master

splite3が本番環境で適用されている時

本番環境ではPostgresqlを用いるようにする

Gemfile

・
・
・

group :development, :test do
  gem 'sqlite3'

 ・
 ・
 ・

end

・
・
・

group :production do
  gem 'pg'

 ・
 ・
 ・

end

Herokuとローカルのbundlerのバージョンが異なる時

ローカルに同じバージョンをインストール

% gem uninstall bundler #ローカルのbundlerをアンインストール
% gem install bundler --version '2.2.11' #デプロイ先のHerokuと同じversionのbundlerをローカルにインストール

% bundler -v #bundlerのversion確認
Bundler version 2.2.4 #意図してたバージョンと違う

% gem list bundler #ローカルにインストールされているbundlerのversionリストを表示

% rm gemfile.lock #Gemfile.lockを削除
% bundle _2.1.4_ install --without production #version指定してbundle install

% git add -A
% git commit -m 'Change Bundler version 2.2.4 to 2.2.11'

% git push heroku master

それでも治らない、、、

上の原因と対処法をやってみたがエラーは治らず。。。

上記以外に原因が?

エラーメッセージちゃんと読めば書いてた。

remote:        Your bundle only supports platforms ["x86_64-darwin-20"] but your local platform
remote:        is x86_64-linux. Add the current platform to the lockfile with `bundle lock
remote:        --add-platform x86_64-linux` and try again.
remote:        Bundler Output: Your bundle only supports platforms ["x86_64-darwin-20"] but your local platform
remote:        is x86_64-linux. Add the current platform to the lockfile with `bundle lock
remote:        --add-platform x86_64-linux` and try again.

指定された通りに

$ bundle lock --add-platform x86_64-linux

を実行。

コミットも忘れずに

$ git add .
$ git commit -m 'Add platform'

すると、Herokuのプッシュに成功!

まじで長かった。。。

参考:
https://yumishin.com/heroku-push-error/#i-4
https://tex2e.github.io/blog/ruby/rails-on-heroku

23
16
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
23
16