由于sqlite3 gem错误,Heroku部署失败

我刚刚开始阅读Michael Hartl撰写的ruby.railstutorial.org书,并一直在完成第一章。 我正在使用mac book OS X,Terminal和Sublime Text。 一切都按计划进行,直到测试部署到Heroku为止。 我能够连接到Heroku并运行$ git push heroku master命令。 但部署失败:

 Installing sqlite3 (1.3.5) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /usr/local/bin/ruby extconf.rb checking for sqlite3.h... no sqlite3.h is missing. Try 'port install sqlite3 +universal' or 'yum install sqlite-devel' and check your shared library search path (the location where your sqlite3 shared library is located). *** 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: An error occurred while installing sqlite3 (1.3.5), and Bundler cannot continue. Make sure that `gem install sqlite3 -v '1.3.5'` succeeds before bundling. ! ! Failed to install gems via Bundler. ! ! Detected sqlite3 gem which is not supported on Heroku. ! http://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development ! ! Heroku push rejected, failed to compile Ruby/rails app 

这是我的Gemfile

 source 'https://rubygems.org' gem 'rails', '3.2.8' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' group :development, :test do gem 'sqlite3', '1.3.5' end # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.5' gem 'coffee-rails', '~> 3.2.2' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.2.3' end gem 'jquery-rails', '2.0.2' group :production do gem 'pg', '0.12.2' end # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' # To use Jbuilder templates for JSON # gem 'jbuilder' # Use unicorn as the app server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger # gem 'debugger' 

我有sqlite3指定开发而不是生产,所以我认为Heroku会一起忽略它,但似乎并非如此。

此外,当我创建捆绑我使用$ bundle install –without production

我知道有些人建议只安装PG并使用它,但我真的想尽可能地坚持本教程,然后我冒险尝试不同的方法。

我此刻有点失落,不知道如何从这里开始。 您可以提供的任何帮助将非常感激。

谢谢

无论出于何种原因,Heroku都无法安装sqlite3 gem。 但你可以告诉bundler除了开发时它不应该尝试。

在你的Gemfile ,将Gemfile gem 'sqlite3'替换为:

 group :development, :test do gem 'sqlite3' end group :production do gem 'pg' end 

然后,作为production运行的heroku上的bundler将不会尝试安装它。

我终于能够成功部署到Heroku。 感谢evanc3指点我在Heroku网站上的一篇文章。 在部署到Heroku之前,我似乎忘了提交我的Gemgile更新。 因此,对于刚刚开始的所有人,您需要确保在部署到Heroku之前提交更改。

Heroku不支持sqlite3 …

从您的Gemfile中删除sqlite3,改为使用pg gem。 请在gem文件中进行以下更改

Gemfile更改以下Gemfile

 gem 'sqlite3' 

 gem 'pg' #you will have to install postgresql 

重要:跑

 git add . git commit git push heroku master 

注意:如果您打算部署heroku,我建议最好在开发阶段使用postgres(在您的计算机上安装postgresql),heroku更喜欢psql。

如果要使用sqllite进行开发,使用postgresql进行Heroku,请使用以下配置。

 group :development do gem 'sqlite3' #gem to use in development environment end group :production do gem 'pg' #gem to use in production environment end 

Heroku将使用pg gem,因为heroku在生产环境中运行您的应用程序

在Heroku上,您的应用无法访问文件系统。 这有很多原因 – 这主要是因为您可以通过添加新实例(即一次运行多个服务器)来扩展应用程序的性能,并且这些实例不能保证在同一台物理计算机上 – 复制跨越的文件将非常慢。

SQLite只是将数据库存储到db /文件夹中的文件,这就是它与Heroku不兼容的原因。

如帮助链接所示,最好的选择是远离SQLite,因为SQLite和PostgreSQL(Heroku的首选数据库)之间有时会出现微妙的不兼容性,并且您希望部署到生产之前找到它!

安装PostgreSQL后(具体如何操作取决于您的操作系统),然后将gem’pg gem 'pg'添加到您的Gemfile中。

我有一个解决方案,如果你没有直接在你的gemfile中使用sqlite3,你仍然会收到此错误。

最有可能的是,你有一个使用sqlite3作为依赖项的gem,它包含了你不知道的gem。

1)转到Gemfile.lock并搜索sqlite。

2)找到使用sqlite的gem,然后将gem移动到开发或测试组中。

3)捆绑