LoginSignup
0
0

More than 3 years have passed since last update.

HerokuがRubyアップデートを推奨するけど、Ruby 2.6をどうしても使いたい。

Last updated at Posted at 2021-02-17

問題

Ruby-2.6.3 で Git から Heroku にデプロイをしようとしたらエラーが出ました。

$ heroku create
Creating app... done, ⬢ heroku20-app-00001.git
...
$ git push heroku main
(中略)
remote: !       Push rejected to ...

経緯と方針

私の参考にしている書籍では Ruby-2.6.3 を使うように指示があったのですが、
デプロイ中に「 Ruby を最新版に更新してください 」と Heroku に以下のように推奨されました。

remote:  !     Heroku recommends you use the latest supported Ruby version listed here:
remote:  !     https://devcenter.heroku.com/articles/ruby-support#supported-runtimes

しかしデプロイが初めての私でしたので、どうしても参考書籍の通りに進めたかったです。
Heroku の推奨に従わないで、どうにかして Ruby-2.6.3 のままでいたいという思いです。

エラー内容抜粋 (冒頭コードの中略の部分)

remote:  !     The Ruby version you are trying to install does not exist on this stack.
remote:  !     
remote:  !     You are trying to install ruby-2.6.3 on heroku-20.
remote:  !     
remote:  !     Ruby ruby-2.6.3 is present on the following stacks:
remote:  !     
remote:  !     - cedar-14
remote:  !     - heroku-16
remote:  !     - heroku-18
remote:  !     

どうやら "You are trying to install ruby-2.6.3 on heroku-20" というように、デプロイ中に heroku-20 を使っていることに問題があるようです。
そして "Ruby ruby-2.6.3 is present on the following stacks:" というように、ruby-2.6.3 では heroku-18 をフォローしているようです。

heroku-20 ではなく、heroku-18 を使う。

heroku-18 を利用するためには以下のコマンドを使います。

$ heroku create --stack heroku-18

(参考:Heroku-18 Stack < https://devcenter.heroku.com/articles/heroku-18-stack#using-heroku-18 >)

実際に打ち込むと、以下のようになりました。

$ heroku create --stack heroku-18
Creating app... done, ⬢ heroku18-app-00001, stack is heroku-18
https://shielded-dusk-28692.herokuapp.com/ | https://git.heroku.com/shielded-dusk-28692.git

heroku18-app-00001 は新しく Heroku 上に作られたアプリの名前です。

リモートリポジトリを調べると、

$ git remote -v
heroku  https://git.heroku.com/heroku20-app-00001.git (fetch)
heroku  https://git.heroku.com/heroku20-app-00001.git (push)

デプロイ先が変わっておらず、heroku-20 のままになっています。
Ruby-2.6.3 の環境のままデプロイするとエラーが出るので、

以下のコマンドで、

$ git remote set-url heroku heroku18-app-00001

新しく作った heroku-18 のアプリにデプロイ先を置き換えます。

もう一度、リモートリポジトリを調べると、

$ git remote -v
heroku  https://git.heroku.com/heroku18-app-00001.git (fetch)
heroku  https://git.heroku.com/heroku18-app-00001.git (push)

これでデプロイ先が heroku-18 に変わりました。

解決

ruby-2.6.3 は heroku-18 をフォローしているので、
これで無事にデプロイが終わるはずです。

$ git push heroku main
(中略)
remote: Verifying deploy... done.
0
0
3

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