0
0

More than 3 years have passed since last update.

HerokuへのPush時に「Failed to install gems via Bundler.」が出た時の対処法

Last updated at Posted at 2021-06-08

RailsチュートリアルでherokuへPushする際以下のようなエラーが出た。

remote: -----> Ruby app detected
remote: -----> Installing bundler 2.2.16
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.6.6
remote: -----> Installing dependencies using bundler 2.2.16
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
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.
remote: 
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote:  !

調べたところ、Heroku環境のbundlerのversionとローカル環境のbundlerのversionが一致していないことが原因らしい。
Herokuのbundlerがバージョン2.2.16なのに対してローカルのバージョンは2.2.19だった。

解決方法

下記のコマンドを順に入力したらうまくいった。

$ gem uninstall bundler
# ローカルのbundlerをアンインストール

$ gem install bundler --version '2.2.16'
# Herokuと同じバージョンのbundlerをインストール

$ bundler -v
# 正しくインストールされたか確認

$ rm Gemfile.lock
# 今あるGemfile.lockを削除する

$ bundle _2.2.16_ install --without production
# bundleをインストール & Gemfile.lockが作成される

$ bundle lock --add-platform x86_64-linux

$ git add -A
$ git commit -m "Change bundler version 2.2.19->2.2.16"

$ git push heroku master

エラー文でググったら似たような事例がたくさん出てきた。

追記

remote:  !     Unknown version "6.1"

このエラーは、Gemfileを書き換えるとうまくいった。

Gemfile
gem 'rails', '6.0.3'

こうする↓

Gemfile
gem 'rails', '6.1.0'
0
0
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
0
0