Heroku:无法通过Bundler安装gem

时间:2015-07-05 23:05:26

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

我尝试使用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 btw:

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

4 个答案:

答案 0 :(得分:4)

按照步骤 -

步骤1:手动或从以下命令 -

中删除项目中的Gemfile.lock
rm -rf ~/.bundle/ ~/.gem/ .bundle/ Gemfile.lock

第2步:然后bundle install

第3步:git add .

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

第5步:git push heroku master -f

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

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

答案 3 :(得分:0)

  1. 确保您在本地安装了posgresSQL:

    • on MAC:

    brew install postgresql

    • 在Ubuntu上:

    sudo apt-get install libpq-dev

    • RHEL系统:

    yum install postgresql-devel

  2. 在您当地的

    上发布postgres

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

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

    postgres -V

  4. 在终端上登录Postgresql

    sudo -u postgres psql postgres

  5. (您可能需要提供密码' root')

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

      创建角色testpostgres WITH LOGIN PASSWORD' root';

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

      ALTER ROLE testpostgres CREATEDB;

    3. 设置新用户的密码

      \ password testpostgres

    4. 创建数据库

      创建数据库yourDBName;

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

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

      1. 登录后,您可能会看到如下图像
      2. enter image description here

        1. 配置您的database.yml

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

          通过在database.yml文件中添加两个字段来提供用户名和密码登录到DB:

          默认值:&默认值   适配器:postgresql   pool:<%= ENV.fetch(" RAILS_MAX_THREADS"){5}%>   主持人:localhost   用户名:testpostgres   密码:root   超时:5000

        2. 可以将数据库名称放在字段数据库中,例如:

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

            rake db:create

            rake db:migrate

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

          3. 参考链接:

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