【问题标题】:Heroku: Failed to install gems via BundlerHeroku:无法通过 Bundler 安装 gem
【发布时间】:2015-09-23 00:14:08
【问题描述】:

我尝试使用 git push heroku master -f 命令将我的 Rails 应用程序推送到 Heroku,我得到了这个:

Total 0 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.0.0
remote: -----> Installing dependencies using 1.9.7
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        You are trying to install in deployment mode after changing
remote:        your Gemfile. Run `bundle install` elsewhere and add the
remote:        updated Gemfile.lock to version control.
remote:        You have added to the Gemfile:
remote:        * rails (= 4.2.0)
remote:        * sass-rails (= 5.0.2)
remote:        * uglifier (= 2.5.3)
remote:        * coffee-rails (= 4.1.0)
remote:        * jquery-rails (= 4.0.3)
remote:        * turbolinks (= 2.3.0)
remote:        * jbuilder (= 2.2.3)
remote:        * sdoc (= 0.4.0)
remote:        * sqlite3 (= 1.3.9)
remote:        * byebug (= 3.4.0)
remote:        * web-console (= 2.0.0.beta3)
remote:        * spring (= 1.1.3)
remote:        * pg (= 0.17.1)
remote:        * rails_12factor (= 0.0.2)
remote:        You have deleted from the Gemfile:
remote:        * byebug
remote:        * coffee-rails (~> 4.1.0)
remote:        * jbuilder (~> 2.0)
remote:        * jquery-rails
remote:        * rails (= 4.2.1)
remote:        * sass-rails (~> 5.0)
remote:        * sdoc (~> 0.4.0)
remote:        * spring
remote:        * sqlite3
remote:        * turbolinks
remote:        * uglifier (>= 1.3.0)
remote:        * web-console (~> 2.0)
remote:        Bundler Output: You are trying to install in deployment mode after changing
remote:        your Gemfile. Run `bundle install` elsewhere and add the
remote:        updated Gemfile.lock to version control.
remote:
remote:        You have added to the Gemfile:
remote:        * rails (= 4.2.0)
remote:        * sass-rails (= 5.0.2)
remote:        * uglifier (= 2.5.3)
remote:        * coffee-rails (= 4.1.0)
remote:        * jquery-rails (= 4.0.3)
remote:        * turbolinks (= 2.3.0)
remote:        * jbuilder (= 2.2.3)
remote:        * sdoc (= 0.4.0)
remote:        * sqlite3 (= 1.3.9)
remote:        * byebug (= 3.4.0)
remote:        * web-console (= 2.0.0.beta3)
remote:        * spring (= 1.1.3)
remote:        * pg (= 0.17.1)
remote:        * rails_12factor (= 0.0.2)
remote:
remote:        You have deleted from the Gemfile:
remote:        * byebug
remote:        * coffee-rails (~> 4.1.0)
remote:        * jbuilder (~> 2.0)
remote:        * jquery-rails
remote:        * rails (= 4.2.1)
remote:        * sass-rails (~> 5.0)
remote:        * sdoc (~> 0.4.0)
remote:        * spring
remote:        * sqlite3
remote:        * turbolinks
remote:        * uglifier (>= 1.3.0)
remote:        * web-console (~> 2.0)
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !
remote:
remote:  !     Push rejected, failed to compile Ruby app
remote:
remote: Verifying deploy....
remote:
remote: !   Push rejected to theorderapp.
remote:
To https://git.heroku.com/theorderapp.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/theorderapp.git'

我再次尝试bundle updatebundle install 并运行git push heroku master -f,但它仍然无法正常工作。

我也尝试删除我的 Gemfile.lock 文件,再次运行 bundle updatebundle installgit addgit commit 并运行 git push heroku master -f,但它也不适合我。

顺便说一句,这是我的 Gemfile:

source 'https://rubygems.org'

gem 'rails',            '4.2.0'
gem 'bootstrap-sass',   '3.2.0.0'
gem 'sass-rails',       '5.0.2'
gem 'uglifier',         '2.5.3'
gem 'coffee-rails',     '4.1.0'
gem 'jquery-rails',     '4.0.3'
gem 'turbolinks',       '2.3.0'
gem 'jbuilder',         '2.2.3'
gem 'sdoc',             '0.4.0', group: :doc
gem 'font-awesome-sass'

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
end

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

这是我的 .gitignore 文件:

# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp

【问题讨论】:

  • 你的 .gitignore 里有什么?它抱怨 Gemfile.lock 在 repo 中没有更新。
  • @Gene 我刚刚添加了我的 .gitignore 文件。
  • 您是否提交了您的GemfileGemfile.lock 修改?
  • 啊!可能是您没有在 gemfile 中指定 ruby​​ 版本。我认为 Heroku 需要这个。所以它使用 ruby​​ 2.0 作为 heroku 默认值,然后尝试为 1.9.7 加载 gems 作为 bundler 默认值。如果这是正确的,在 gemfile 中指定 ruby​​ 版本号将解决问题。见devcenter.heroku.com/articles/ruby-versions

标签: ruby-on-rails ruby ruby-on-rails-4 heroku gemfile


【解决方案1】:

按照步骤-

第 1 步:手动或通过以下命令从项目中删除 Gemfile.lock -

rm -rf ~/.bundle/ ~/.gem/ .bundle/ Gemfile.lock

第二步:然后bundle install

第三步:git add .

第四步:git commit -m "commiting Gemfile.lock"

第 5 步:git push heroku master -f

【讨论】:

  • 这不是个坏主意吗?不需要 Gemfile.lock 吗?
  • @sabaeus 我相信 gemfile.lock 是在bundle install 之后生成的。如果我理解正确,我认为用户正在尝试“重置”gemfile.lock。
【解决方案2】:

先做一个“git pull”合并,然后再push。 或尝试执行此操作: rake assets:precompile git add . git commit -m "Add precompiled assets for Heroku" git push heroku master -f

【讨论】:

  • 当我执行git pull 时,我会收到Already up-to-date. 消息。然后我做rake assets:precompile -> git add . -> git commit -m "Add precompiled assets for Heroku" -> git push heroku master -f。仍然得到同样的错误:Failed to install gems via Bundler..
  • 如果你确定你在做什么,你可以强制推送到 heroku: git push --force heroku master
  • 我运行rake bundle update 并得到这个:rake aborted!不知道如何构建任务“bundle”(通过使用 --trace 运行任务查看完整跟踪)
  • git push --force heroku master 也给出相同的Failed to install gems via Bundler. 错误。
  • @Akshay Chavan 我也有同样的问题安装 json (1.8.0) 时发生错误,并且运行 git push heroku master 时 Bundler 无法继续......如果你有解决的想法这??????。
【解决方案3】:
  1. 通过以下方式确保您已在本地安装 posgresSQL:

    • 在 MAC 上:

    brew 安装 postgresql

    • 在 Ubuntu 上:

    sudo apt-get install libpq-dev

    • RHEL 系统:

    yum 安装 postgresql-devel

  2. 在本地启动 postgres

    pg_ctl -D /usr/local/var/postgres start && brew services star postgresql

  3. 让我们确保 Postgres 已安装并正在运行

    postgres -V

  4. 在终端上登录 Postgresql

    sudo -u postgres psql postgres

(您可能需要提供密码“root”)

  1. 创建用户 Postgres 实际上并不像大多数标准权限模型那样直接管理用户或组。相反,它直接管理它所谓的角色

    使用登录密码“root”创建角色 testpostgres;

  2. 为我们的新用户分配 createDB 权限

    ALTER ROLE testpostgres CREATEDB;

  3. 为新用户设置密码

    \密码testpostgres

  4. 创建你的数据库

    创建数据库您的数据库名称;

  5. 使用带有 UI 的 Postico (eggerapps.at/postico/) 来管理 PostgresDB。

上面的用户用户设置通过 Postico 登录到您的数据库。

  1. 登录后,您可能会看到如下图

enter image description here

  1. 配置你的 database.yml

    将所有适配器 :sqlite3 更改为适配器 :postgresql

    通过在您的 database.yml 文件中添加两个字段来提供登录数据库的用户名和密码,例如:

    默认值:&默认值 适配器:postgresql 池: 主机:本地主机 用户名:testpostgres 密码:root 超时:5000

随意将您的数据库名称与字段数据库一起输入,例如:

production:
  <<: *default
  database: railsapp
  1. 运行

    耙数据库:创建

    rake db:迁移

  2. 再次提交并将代码推送到 Heroku。应该没问题。

参考链接:

https://www.codementor.io/devops/tutorial/getting-started-postgresql-server-mac-osx

【讨论】:

    【解决方案4】:

    我很确定您没有在 gemfile 中指定 ruby​​ 版本。我相信 Heroku 需要这个。所以它使用 ruby​​ 2.0 作为 heroku 默认值,然后尝试为 1.9.7 加载 gems 作为 bundler 默认值。

    如果这是正确的,在 gemfile 中指定 ruby​​ 版本号将解决问题。见http://devcenter.heroku.com/articles/ruby-versions

    【讨论】:

      猜你喜欢
      • 2019-01-07
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 2011-06-02
      相关资源
      最近更新 更多