简体   繁体   中英

Heroku: Failed to install gems via Bundler

I try to push my Rails app to Heroku using git push heroku master -f command and I get this:

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'

I try to bundle update and bundle install again and run git push heroku master -f but it's still not working.

I also try delete my Gemfile.lock file, run bundle update and bundle install again, git add and git commit it and run git push heroku master -f but it also not working for me.

This is my 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

And this is my .gitignore file:

# 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

Follow steps -

Step 1: Remove Gemfile.lock from your project by manually or from following command -

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

Step 2: Then bundle install

Step 3: git add .

Step 4: git commit -m "commiting Gemfile.lock"

Step 5: git push heroku master -f

First do a "git pull" to merge, and then push again. or try to Execute this: rake assets:precompile git add . git commit -m "Add precompiled assets for Heroku" git push heroku master -f rake assets:precompile git add . git commit -m "Add precompiled assets for Heroku" git push heroku master -f

  1. to make sure you have install posgresSQL on your local by:

    • on MAC:

    brew install postgresql

    • on Ubuntu:

    sudo apt-get install libpq-dev

    • RHEL systems:

    yum install postgresql-devel

  2. Start the postgres on your local

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

  3. Let's make sure Postgres is installed and running

    postgres -V

  4. Login to Postgresql on terminal

    sudo -u postgres psql postgres

(You may need to provide the password 'root' )

  1. Create user Postgres doesn't actually directly manage users or groups, like most standard permission models do. Instead, it directly manages what it calls roles

    CREATE ROLE testpostgres WITH LOGIN PASSWORD 'root';

  2. Assign createDB permission to our new user

    ALTER ROLE testpostgres CREATEDB;

  3. Set password for new user

    \\password testpostgres

  4. Create your DB

    CREATE DATABASE yourDBName;

  5. Used Postico (eggerapps.at/postico/) with UI to manage PostgresDB.

User user setup above to login to your DB via Postico.

  1. After logged in, you may see the image like below

enter image description here

  1. Config your database.yml

    Change all adapter :sqlite3 to adapter :postgresql

    Provide the username and password login to DB by added two fields to your database.yml file like:

    default: &default adapter: postgresql pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> host: localhost username: testpostgres password: root timeout: 5000

Fell free to put your DB name with the field database, like:

production:
  <<: *default
  database: railsapp
  1. Run

    rake db:create

    rake db:migrate

  2. Commit and push code to Heroku again. It should be Ok.

References links :

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

I'm pretty sure it's that you don't specify the ruby version in your gemfile. I believe Heroku needs this. So it's using ruby 2.0 as the heroku default and then trying to load gems for 1.9.7 as the bundler default.

If this is right, specifying the ruby version number in the gemfile will fix the problem. See http://devcenter.heroku.com/articles/ruby-versions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM