将 rails 应用程序部署到 heroku 时出错
error while deploying rails app to heroku
我是 rails 和 heroku 的新手
我尝试了以下代码将我的应用程序推送到 heroku
rails new snippets
cd snippets
git init
git add .
git commit -m "initial commit"
wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
heroku create
git push heroku master
但我收到以下错误
An error occurred while installing sqlite3 (1.3.10), and Bundler cannot
remote: continue.
remote: Make sure that `gem install sqlite3 -v '1.3.10'` succeeds before bundling.
remote: !
remote: ! Failed to install gems via Bundler.
remote: !
remote: ! Detected sqlite3 gem which is not supported on Heroku.
remote: ! https://devcenter.heroku.com/articles/sqlite3
remote: !
remote:
remote: ! Push rejected, failed to compile Ruby app
remote:
remote: Verifying deploy....
remote:
remote: ! Push rejected to powerful-waters-8202.
remote:
To https://git.heroku.com/powerful-waters-8202.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/powerful-waters-8202.git'
我将我的 gemfile 修改为::
group :devlopment, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
当我 运行 捆绑包安装时
我收到以下错误
Installing pg 0.18.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150705-24664-1i1n8se.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/user/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
extconf failed, exit code 1
Gem files will remain installed in /home/user/.rvm/gems/ruby-2.2.1/gems/pg-0.18.2 for inspection.
Results logged to /home/user/.rvm/gems/ruby-2.2.1/extensions/x86_64-linux/2.2.0/pg-0.18.2/gem_make.out
An error occurred while installing pg (0.18.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.2'` succeeds before bundling.
我尝试使用命令
gem install pg -v '0.18.2'
现在我收到以下错误
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
这是我的 database.yml 文件
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
和我的 gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
###################################################################################
group :development, :test do # <<<< :development, not devlopment
gem 'sqlite3'
end
group :production do
gem 'pg'
end
##################################################################
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
谁能帮我解决这个问题??
如果您要继续 运行ning SQLite 开发,运行
bundle install --without production
这将阻止 Bundler 尝试安装 pg
,但 Heroku 会在您部署时安装 pg
,因为它们 运行 --without development,test
.
如果你想在本地切换到 Postgres,Whosebug 有很多帮助,我不会在这里重复:
- How to install PostgreSQL's pg gem on Ubuntu?
- Installing PG gem on OS X - failure to build native extension
- ERROR: Failed to build gem native extension on Mavericks
- Can't install pg gem on Windows
正如您提到的 Ubuntu 14.04.2 LTS,请尝试以下命令
sudo apt-get install libpq-dev
然后
gem install pg -v '0.18.2'
更新:
您还应该将 适配器 更改为 postgresql for production 在你的 database.yml
production:
adapter: postgresql
pool: 5
timeout: 5000
你在这里已经有一些很好的建议,但我会添加我没有看到的内容。
我对您的建议是在开发中使用与生产中相同的数据库 PostgreSQL。这是一个好主意的原因有很多,而您刚刚遇到了一个令人头疼的部署问题。
但是假设您坚持使用不同的数据库类型。你的 gemfile 中的这一行对我来说很奇怪-- "not devlopment"
#
#
###################################################################################
group :development, :test do # <<<< :development, not devlopment
gem 'sqlite3'
end
我觉得你应该试试
#
#
###################################################################################
group :development, :test do
gem 'sqlite3'
end
告诉我进展如何。
我是 rails 和 heroku 的新手 我尝试了以下代码将我的应用程序推送到 heroku
rails new snippets
cd snippets
git init
git add .
git commit -m "initial commit"
wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
heroku create
git push heroku master
但我收到以下错误
An error occurred while installing sqlite3 (1.3.10), and Bundler cannot
remote: continue.
remote: Make sure that `gem install sqlite3 -v '1.3.10'` succeeds before bundling.
remote: !
remote: ! Failed to install gems via Bundler.
remote: !
remote: ! Detected sqlite3 gem which is not supported on Heroku.
remote: ! https://devcenter.heroku.com/articles/sqlite3
remote: !
remote:
remote: ! Push rejected, failed to compile Ruby app
remote:
remote: Verifying deploy....
remote:
remote: ! Push rejected to powerful-waters-8202.
remote:
To https://git.heroku.com/powerful-waters-8202.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/powerful-waters-8202.git'
我将我的 gemfile 修改为::
group :devlopment, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
当我 运行 捆绑包安装时 我收到以下错误
Installing pg 0.18.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150705-24664-1i1n8se.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/user/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
extconf failed, exit code 1
Gem files will remain installed in /home/user/.rvm/gems/ruby-2.2.1/gems/pg-0.18.2 for inspection.
Results logged to /home/user/.rvm/gems/ruby-2.2.1/extensions/x86_64-linux/2.2.0/pg-0.18.2/gem_make.out
An error occurred while installing pg (0.18.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.2'` succeeds before bundling.
我尝试使用命令
gem install pg -v '0.18.2'
现在我收到以下错误
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
这是我的 database.yml 文件
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
和我的 gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
###################################################################################
group :development, :test do # <<<< :development, not devlopment
gem 'sqlite3'
end
group :production do
gem 'pg'
end
##################################################################
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
谁能帮我解决这个问题??
如果您要继续 运行ning SQLite 开发,运行
bundle install --without production
这将阻止 Bundler 尝试安装 pg
,但 Heroku 会在您部署时安装 pg
,因为它们 运行 --without development,test
.
如果你想在本地切换到 Postgres,Whosebug 有很多帮助,我不会在这里重复:
- How to install PostgreSQL's pg gem on Ubuntu?
- Installing PG gem on OS X - failure to build native extension
- ERROR: Failed to build gem native extension on Mavericks
- Can't install pg gem on Windows
正如您提到的 Ubuntu 14.04.2 LTS,请尝试以下命令
sudo apt-get install libpq-dev
然后
gem install pg -v '0.18.2'
更新:
您还应该将 适配器 更改为 postgresql for production 在你的 database.yml
production:
adapter: postgresql
pool: 5
timeout: 5000
你在这里已经有一些很好的建议,但我会添加我没有看到的内容。
我对您的建议是在开发中使用与生产中相同的数据库 PostgreSQL。这是一个好主意的原因有很多,而您刚刚遇到了一个令人头疼的部署问题。
但是假设您坚持使用不同的数据库类型。你的 gemfile 中的这一行对我来说很奇怪-- "not devlopment"
#
#
###################################################################################
group :development, :test do # <<<< :development, not devlopment
gem 'sqlite3'
end
我觉得你应该试试
#
#
###################################################################################
group :development, :test do
gem 'sqlite3'
end
告诉我进展如何。