Rails 3.2 from SQLite locally to Postgres on Heroku - ruby-on-rails

I've developing an app locally with sqlite but now want to move it to Heroku, so I will use postgres from now on. I don't need to keep the database as it is so far, I just need Heroku to not try to install Sqlite because it blows up like so:
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.
I have changed my database.yml file and switched 'gem' "sqlite3" to 'gem' "pg" in my Gemfile, but heroku is still mad. What else needs to change so it doesn't try to install sqlite3 when I commit my app?

Once you've changed your Gemfile to use gem 'pg' then you need to rerun the bundle command. Once you've done that, commit your Gemfile and Gemfile.lock to git and then push the application to Heroku and it should work.
If you don't run Postgres locally then you should add gem 'pg' to your production group in your Gemfile else when you run bundle locally you'll have issues when it tries to compile the gem. You could safely move gem 'sqlite' to a development group in your Gemfile to use different DBs between environments. But bewarned it's safest to run the same DB locally when as you are deploying to.

Related

Pushing to heroku fails due to sqlite3 on Mac

I've seen multiple questions, all with the same problems as me. I tried all the solutions proposed, such as making the following my Gemfile
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
Added, committed, and nothing. Still the same issue when I run git push heroku master:
em::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
tmp/build_d2c698fb-cf76-40cd-b046-9866c3432e8b/vendor/ruby-2.0.0/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
I tried installing Xcode to see if that solves it, but it didn't. Ran brew install sqlite3 which also didn't solve it.
I also checked the dependencies of my gems in my Gemfile, with gem dependency and also checking the Gemfile.lock file, which shows no dependencies for the sqlite3 gem.
I can't find a solution to this problem from existing questions. Maybe I skimmed over something I am missing, but I can't find it.
Some extra information:
$ rails -v
Rails 4.1.1
$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-darwin13.1.0]
$ gem -v
2.2.2
$ sqlite3 -version
3.7.13 2012-07-17

Error with gem pg shouldn't happen locally, only in production, why is bundle installing it?

I have a Ruby on Rails application and am just starting to deploy it to Heroku.
The Heroku quick start guide says to include the pg gem for your database on production. OK, this came up the last time I deployed to Heroku, and I solved it with the following:
group :production do
gem 'pg'
end
However, this time around, when I try to "bundle install" or "bundle update" my app locally, it is for some reason trying to install pg, even though I explicitly told it to only use pg in production! Any reason why this is, and what can I do to fix it? Thanks!
Installing pg (0.13.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
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.
Try running
bundle install --without production
This will prevent production gems being bundled, and the setting will stick for normal bundle commands until the next time your use the --without parameter.

Rails - Not uploading to heroku after upgrading ruby to 1.9.3 and rails to 3.2

I had this app using 1.9.2 and rails 3.2
and today I changed the ruby version into 1.9.3 (using rbenv)
and everything went wrong then
I had this on my gemfile
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
Everytime I run:
bundle install --without production
Nothing happens now and when I do
git push heroku master
I get the same error:
Installing sqlite3 (1.3.5) with native extensions Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Thanks!
/usr/local/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/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:
Its obviously trying to install sqlite, but even if I remove the sqlite gem from my Gemfile nothing happens, seems that the problem is in heroku but now I can't do nothing
Hope someone can help me because I was trying to do
heroku db:pull
and because of that I wanted to add the taps gem, then I followed this tutorial
http://railsapps.github.com/rails-heroku-tutorial.html
And I changed the version of ruby in heroku, now I think that the problem is rbenv but I'm not sure
Thanks in advance
Javier Q
Actually in order to get all the db I only had to do:
gem install taps
and not to put it into the Gemfile because it requires sqlite3

Rails 3.1 Sqlite3 Error On Push To Heroku

I have a rails 3.1 app that i am trying to push to Heroku. It keeps failing when i push it.
Installing sqlite3 (1.3.4) with native extensions Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Thanks!
/usr/local/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/usr/local/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite3-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
I changed my gem file to have the following lines:
gem 'sqlite3', :group => [:development, :test]
gem 'pg', :group => [:production]
Even after running bundle install etc i am getting the error. I even ran some tests without sqlite3 in my gem file and it still tries to install it on Heroku. Any suggestions?
Lol it turns out i was working on one branch and was pushing my master. Once i merged them and pushed the correct branch everything worked great.
The Cedar stack doesn't yet support bundle without according to the docs, http://devcenter.heroku.com/articles/bundler so it will still attempt to install it on deployment.
To be honest, you'd be much better using postgres locally if that is what you're deploying too.

Trouble Getting the Rails Server Started

When I run 'rails server' I get the following error:
Could not find gem 'sqlite3 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
My GemFile looks like this: gem 'sqlite3'
Also when I run the port command it says it does not recognize that command:
Mohammad-Azams-MacBook-Pro:blog azamsharp$ port install sqlite3 +universal
-bash: port: command not found
Any suggestions?
UPDATE 1:
I run sudo gem install sqlite3 and got the following message:
Mohammad-Azams-MacBook-Pro:blog azamsharp$ sudo gem install sqlite3
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite3-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.
UPDATE 2: (Contents of GemFile)
source 'http://rubygems.org'
gem 'rails', '3.0.7'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
UPDATE 3:
Mohammad-Azams-MacBook-Pro:blog azamsharp$ port search sqlite3
-bash: port: command not found
UPDATE 4:
After downloading the install Macports I ran the bundle install again and here is the result:
Installing sqlite3 (1.3.3) with native extensions /usr/local/lib/ruby/site_ruby/1.8/rubygems/installer.rb:483:inbuild_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/usr/local/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite3-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.
`
UPDATE 5:
which sqlite3 gives me the following:
Mohammad-Azams-MacBook-Pro:blog azamsharp$ which sqlite3
/opt/local/bin/sqlite3
UPDATE 5:
which -a sqlite3 gives me the following:
Mohammad-Azams-MacBook-Pro:blog azamsharp$ which -a sqlite3
/opt/local/bin/sqlite3
/usr/local/bin/sqlite3
/usr/bin/sqlite3
If you have problems talking about /usr/local/bin/ruby extconf.rb checking for sqlite3.h then it's probably something to do with macports.
First, make sure you have xcode installed. Run:
gcc
and you should get:
i686-apple-darwin10-gcc-4.2.1: no input files
If you do, then let's install homebrew
Then, a list of commands to install homebrew, update rubygems, and upgrade rails
brew install sqlite
gem update --system
gem install bundler
gem install rails -v=3.0.8
Then, to check, rails -v should output Rails 3.0.7
If you are running 10.4 or earlier you don't have sqlite 3 (the actual DB engine, not the gem) installed by default. You have 3 options (assuming upgrading your OS to 10.5 or 10.6 is not an option):
Compile the source (not as bad as it sounds) http://www.sqlite.org/download.html
Install MacPorts (why the port command was not found) http://www.macports.org/install.php
Don't use sqlite. Instead use mysql or another DB of your choice.
I recommend the latter if you are going to deploy using some DB other than sqlite, and deploying with sqlite generally isn't a good idea. I like to keep my development and production environments fairly uniform to help avoid gotchas and such.
I hope this helps.
I'm summing up in a reply. So :
1) Install macports : http://www.macports.org/install.php - It has a dmg installer, will take 2 minutes.
2) Once you have it installed, do a 'bundle install' and sqlite3 will be installed as specified in your Gemfile.
When you use port look for a package called sqlite3-dev or something similar to that. The -dev part is key. I don't use MacPorts, but on my Ubuntu install this is the needed package.
When you want to install a package that you plan to link against, always look for the -dev version. The -dev means that it installs the header files among other things that are needed for development against that package.
Most likely your gem cannot build the sqlite3 native extension because it is looking for the header files, if this does not solve your problem please post the log file for the gem installation.
From your Rails directory:
cd ..
cd rails-root
ruby -v
gem list sqlite3
bundle install
gem list sqlite3
bundle exec rails server
What might be happening is you're bundling in a Rails app that has an .rvmrc file. I've seen cases where you bundle under a version of Ruby that doesn't match the .rvmrc file or some other mismatch so when you bundle sqlite3 it isn't under the same version of Ruby that rails is using when you run the app.
Changing out of the directory and back into it, and running rails server prefixed with bundle exec are my two suggestions.
there were several links about your problem :
Install sqlite3 on mac osx?
Snow Leopard & Ruby on Rails - SQLite3 issue
http://railsforum.com/viewtopic.php?id=23018

Resources