You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku-20栈安装ruby-2.6.3失败,修改Gemfile版本后推送仍报错求助

解决Heroku Ruby应用部署失败的思路

Hey there! Let's work through your deploy issues together—here's what's going wrong and how to fix it:

1. 核心问题:Ruby版本与Heroku栈不兼容

从错误日志里能明确看到关键提示:

! The Ruby version you are trying to install does not exist on this stack.
! You are trying to install ruby-2.6.3 on heroku-20.

Ruby 2.6.3并不支持Heroku-20这个运行栈,它仅兼容cedar-14、heroku-16、heroku-18这几个旧栈。你有两个可行的解决方案:

方案A:升级Ruby到Heroku-20支持的版本

Heroku-20支持Ruby 2.7及以上的稳定版本(比如2.7.8、3.0.6、3.1.4这类),操作步骤如下:

  • 打开你的Gemfile,找到开头的ruby声明,把它改成符合要求的版本,举个例子:
    ruby "3.0.6"
    
  • 本地运行bundle install更新Gemfile.lock文件
  • 提交修改:git add Gemfile Gemfile.lock && git commit -m "Update Ruby version for Heroku-20 compatibility"
  • 再次推送代码到Heroku:git push heroku master

方案B:切换Heroku应用的运行栈到支持Ruby 2.6.3的版本

如果你暂时不想升级Ruby,可以把应用的运行栈切换到heroku-18(这是支持Ruby 2.6.3的较新栈):

  • 在终端运行命令:heroku stack:set heroku-18
  • 确认栈切换完成后,再推送代码:git push heroku master

2. 次要问题:重复构建版本警告

日志里还提到你推送的代码版本已经被构建过了,这通常是分支部署的小问题:

  • 如果你是在本地非master分支开发,要指定正确的推送命令,把本地分支推送到Heroku的master分支:git push heroku <你的本地分支名>:master(如果你的Heroku应用默认分支是main,就把master换成main)
  • 如果是在同一个分支操作,先确认你修改的代码已经提交到本地Git仓库,再执行推送命令。

附你提供的部署日志:

Counting objects: 133, done.
Compressing objects: 100% (109/109), done.
Writing objects: 100% (133/133), 152.51 KiB | 3.81 MiB/s, done.
Total 133 (delta 14), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----&gt; Building on the Heroku-20 stack
remote: -----&gt; Ruby app detected
remote: -----&gt; Installing bundler 2.1.4
remote: -----&gt; Removing BUNDLED WITH version in the Gemfile.lock
remote: -----&gt; Compiling Ruby/Rails
remote: Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-20/ruby-2.6.3.tgz -s -o - | tar zxf - ' failed on attempt 1 of 3.
remote: Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-20/ruby-2.6.3.tgz -s -o - | tar zxf - ' failed on attempt 2 of 3.
remote:
remote: !
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: !
remote: ! Heroku recommends you use the latest supported Ruby version listed here:
remote: ! https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote: !
remote: ! For more information on syntax for declaring a Ruby version see:
remote: ! https://devcenter.heroku.com/articles/ruby-versions
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: 5cf5d180a3b3f6f75291fac84f9be0b99d863efc
remote: !
remote: ! We have detected that you have triggered a build from source code with version 5cf5d180a3b3f6f75291fac84f9be0b99d863efc
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku &lt;branchname&gt;:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to afternoon-garden-77939.
remote: To https://git.heroku.com/afternoon-garden-77939.git
! [remote rejected] master -&gt; master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/afternoon-garden-77939.git'

内容的提问来源于stack exchange,提问作者dgb2021

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 08:02:32