Heroku deployment failed because of sqlite3 gem error

17,333

Solution 1

Heroku can't install the sqlite3 gem, for whatever reason. But you can tell bundler that it shouldn't be trying to except when developing.

In your Gemfile, replace gem 'sqlite3' with:

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

Then bundler on heroku, running as production, won't try to install it.

Solution 2

I was finally able to deploy successfully to Heroku. Thanks to evanc3 for pointing me to an article on the Heroku site. It appears that I simply forgot to commit my Gemgile updates before deploying to Heroku. So for all of you just starting out, you need to make sure you commit your changes before deploying to Heroku.

Solution 3

On Heroku, your app doesn't have access to the filesystem. There's a number of reasons for this - it's basically due to the fact that you can scale your app's performance by adding new instances (i.e. running multiple servers at once), and these instances aren't guaranteed to be on the same physical machine - copying the files across would be extremely slow.

SQLite just stores the database to a file in your db/ folder, which is why it's incompatible with Heroku.

The best option, as suggested in the help link, is to move away from SQLite, because there are sometimes subtle incompatibilities between SQLite and PostgreSQL (Heroku's database of choice) and you want to find this out before you deploy to production!

After you install PostgreSQL (exactly how to do this depends on your OS) and then add gem 'pg' to your Gemfile.

Share:
17,333
xuamox
Author by

xuamox

Updated on June 03, 2022

Comments

  • xuamox
    xuamox almost 2 years

    I just started the ruby.railstutorial.org book by Michael Hartl and have been working through the first chapter. I am using mac book OS X, Terminal, and Sublime Text. Everything has gone according to plan, up until it was time to test deployment to Heroku. I am able to connect to Heroku and run the $ git push heroku master command. But the deployment fails:

    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
    

    Here is my 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'
    

    I have sqlite3 designated for development and not production, so I thought Heroku would just ignore it all together, but that does not seem to be the case.

    Also, when i create the bundle i am using $ bundle install --without production

    I know that some people has suggested to just install PG and use that, but I really want to stick to the tutorial as much as possible, before I venture out and try a different approach.

    I am a bit lost at the moment, and not sure how to proceed from here. Any help that you can provide would be most appreciated.

    Thanks

  • xuamox
    xuamox over 11 years
    I updated Gemfile with code, and bundled and deployed to Heroku but I am still getting the same error.
  • xuamox
    xuamox over 11 years
    gem install of sqlite3 was successful, as was the bundle without production, and still no luck
  • Chowlett
    Chowlett over 11 years
    Silly me, I forgot to add the pg gem as a replacement. How about now?
  • xuamox
    xuamox over 11 years
    I just added my Gemgfile to my question. I am flagging sqlite as development and PG as production - but I still get the same error when trying to deploy to Heroku.