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
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.
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.
Heroku do not support sqlite3...
Remove sqlite3 from your Gemfile, use pg gem instead. Do following change in gem file
change following in your Gemfile
gem 'sqlite3'
to
gem 'pg' #you will have to install postgresql
Important: Run
git add .
git commit
git push heroku master
Note: If you are planning to deploy for heroku, I suggest it is better to use postgres in your development phase also(install postgresql in your computer), heroku prefer psql.
If you want to use sqllite for development and postgresql for Heroku, use following config.
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 will use pg gem since heroku run your application in production enviroment
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.
I have a solution for if you don't have sqlite3 directly in your gemfile and you're still getting this error.
Most likely, you have a gem that uses sqlite3 as a dependency and it's including the gem without you knowing.
1) Go to Gemfile.lock and do a search for sqlite.
2) Locate which gem is using sqlite then move the gem into the development or test group.
3) Bundle
In Rails Tutorial they have you using sqlite3 in development & pg in production. One reason heroku deployment may fail is if your production deployment on heroku still references sqlite in your database.yml rather than postgres.
tldr; your config/database.yml should match the one shown here:
https://github.com/mhartl/sample_app_6th_ed/blob/main/config/database.yml
most importantly your production config lines should match this (so that adapter: postgres rather than adapter: sqlite3):
production:
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
database: sample_app_production
Related
I am trying to use postgresql with Ruby on Rails on Heroku but got an error
Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
Please help me to solve this issue.
This worked for me
gem 'pg', '~> 0.20'
Thanks to Piers C
Got this answer from
Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE
In your Gemfile
group :production do
gem 'pg'
end
Then run bundle install and try to deploy on Heroku.
If you want to use PostgreSQL on all environments and not only in production (recommended) add the gem outside the :production group and remove other database adapters such as sqlite.
As a side note, you may also want to add the rails_12factor gem as suggested by Heroku.
Add pg in gemfile
gem 'pg', '~> 0.20'
then bundle update & commit Gemfile & Gemfile.lock to heroku.
simple include like gem 'pg' will not work.
I added the following version into my gemfile, and it is solved.
gem "pg", "~> 0.18"
I've finished creating my blog in Rails through following this tutorial: http://tutorials.jumpstartlab.com/projects/blogger.html
When I deployed my app to Heroku, I keep getting errors that prevented me from deploying. I've fixed my Gemfile, but I'm still getting the same error.
Here is what the terminal gave me:
An error occurred while installing sqlite3 (1.3.9), and Bundler cannot continue.
Make sure that gem install sqlite3 -v '1.3.9' succeeds before bundling.
!
! Failed to install gems via Bundler.
!
! Detected sqlite3 gem which is not supported on Heroku.
!
! Push rejected, failed to compile Ruby app
Here is what i fixed in my Gemfile:
group :development, :test do
gem 'sqlite3'end
Heroku recommends to use Postgresql instead of sqlite: https://devcenter.heroku.com/articles/sqlite3
so replace gem 'sqlite3'
with
gem 'pg'.
Furthermore, make sure that you use the gem in production. Your example only uses the sqlite gem in :development and in :test.
The result would be:
group :development, :test, :production do
gem 'pg'
end
you could also only use postgres in production:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pq'
end
However, it is probably best to use the same database in development and production, to avoid any surprises later on.
I'm trying to deploy an app to heroku. I'm running an ubuntu VM. I just had a lot of trouble getting postgres set up, but I think I'm good to go with that.
I've run
heroku create
and i've committed the most recent changed upon my master branch. When I run bundle install - everything is ok. And when I run
git push heroku master
Everything is smooth, including the installing of the gems. Until I reach the line
------> Writing config/database.yml to read from DATABASE_URL
Everything stalls and I'm greeted with this message 15 minutes later
Timed out compiling ruby app (15 minutes)
for good measure here is my database.yml code
development:
adapter: postgresql
database: saasbook
pool: 5
password:
And here is my gem file
gem 'rails', '4.0.2'
gem 'rails_12factor' , group: :production
gem 'pg'
gem 'saas-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'oauth2'
gem 'figaro'
gem 'rake'
gem devise'
gem 'bootstrap-sass'
gem 'rails_layout'
gem 'zxing'
gem 'rmagick'
gem 'carrierwave'
gem 'rqrcode_png'
ruby "2.0.0"
The heroku deployment tutorial stated to insert the line ruby "2.0.0" after bundle install, and before the commit. I am currently running ruby 1.9.3 if that matters/ would have a conflict.
Any suggestions would be a huge help! thanks!
Edit
I'll leave this out here in case this problem ever arises again for someone
Alas, heroku doesn't like java/C dependent gems, and the QR decoding gem ZXING cannot be used on heroku, that was the reason it was stalling.
For starters, you're missing a quote in your Gemfile for devise:
gem devise' should be gem 'devise'
I would also recommend moving the ruby "2.0.0" line to the top of the Gemfile. It may not matter, but it's worth a shot.
Could be a network issue. Be sure the network you are using has all the appropriate ports open for GIT and heroku. You will need more than port 80.
I am sure you solved this already but for ref:
Make sure that your IDE (mine is RubyMine) is not open on that project or the build will stall/fail.
I'm learning Ruby on Rails from Michael Hartl's website. I have a Gemfile that looks like this:
source 'https://rubygems.org'
ruby '2.0.0'
#check and remove below if not relevant
#ruby-gemset=railstutorial_rails_4_0
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
.
.
.
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Why is this sequence of commands correct:
`$ bundle install --without production`
`$ bundle update`
`$ bundle install`
Shouldn't it first be bundle update then bundle install --without production. Why call bundle install twice? I think the second call is redundant.
Why is this sequence of commands correct:
$ bundle install --without production $ bundle update $ bundle install
Without context, it's difficult to answer this—but one can intuit from the commands that it probably doesn't appear as one string of commands to be executed dutifully.
bundle install --without production installs exactly the versions in your lockfile, skipping any gems in a production group or with a production tag. This allows you to install only what you need to test and develop your application. (e.g., you probably don't want to waste lines with your logging service or pollute your monitoring service.) More importantly, this gives you a known-good working state for development on any machine you use.
bundle update updates the lockfile with permissible newer versions of the gems in the Gemfile. This can and will break your application if the Gemfile has not been well-crafted and versions of your dependencies have changed in the mean time. (So to answer your other question, no, you wouldn't run an update before an install.)
bundle install is most likely there to illustrate the correct command for deploying your production application: It wouldn't make any sense to skip the production gems and immediately turn around to install the production gems.
Where actually are these stuff being downloaded saved? Where are they
being installed? On my computer? I never got where they actually go or
hide. Maybe in my applications folder? But where exactly?
On your computer, in your Ruby installation. Ruby, like Perl and Python, maintains a portion of its directory structure specifically for add-on libraries.
In Ruby 2.0.0, for example, they live someplace similar to [RUBY_ROOT]/lib/ruby/gems/2.0.0/gems. For very specific purposes, it's also possible to install them locally in your Rails application's directory.
My recommendation is
1) Just do bundle, forget the rest. Not important to your learning
2) bundle install
OK, so for whatever version of ruby you are currently using this will take your Gemfile and get the right versions of those gems from rubygems.org (the site). and then install those gems on your machine for version of ruby that you are using if that version doesn't already exist on your machine. If the version exist, no download is needed, the gem version will be able to be immediately included, e.g. when offline.
If you switch ruby version then you'll usually need to bundle install again to get the right versions of those gems for the version of ruby that is currently being used on your machine.
If you use a tool such as rvm to manage your ruby versions then this is as simple as:
cd the_application_directory_for_your_rails_application
rvm use 1.9.3
bundle install
then to switch to ruby 2.0
rvm use 2.0
bundle install
You can specify specific ruby versions with
rvm use 1.9.3-p448 # e.g. for the -p448 version
You can see the 'currently available' ruby versions on your machine with
rvm list rubies
You can install a specific ruby with, e.g.
rvm install 1.9.3-p194
Having the following issue, BRAND NEW TO RoR, first time ever trying to upload an app to go live, first had hosting issues, then decided if i could fix them with heroku i would just use a custom domain with heroku...... No this isnt a test app "learning rails" thing, actual app i want to deploy for use within the business I own, any help would be great, I have searched and havent seen a solution to this problem.
Make sure 'gem install sqlite3 -v 1.3.7' succeeds before bundling.
Failed to install gems via Bundler
Heroku push rejected, failed to compile Ruby/rails app
To git#heroku.com:peaceful-chamber-6371.git
[remote rejected] master -> master <pre-receive hook declined>
error: failed to push some refs to 'git#heroku.com:peaceful-chamber-6371.git
Gem File
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'twitter-bootstrap-rails'
end
gem 'jquery-rails'
# 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'
try this,
remove Gemfile.lock file and do bundle install , then git add, git commit and git push .
Look though the all of the output that Heroku writes to the console -- your error is likely to be there somewhere. I ran into this and found that the precompile step had failed. That can be run locally as well:
rake assets:precompile
Although the question has an accepted answer, the answer did not help me,
I had the same problem. The following worked for me, hence contributing. Heroku does not support sqlite 3. In this case, I had sqlite3 gem in my gemfile, which you are supposed to put in development group, and put postgres gem (which heroku supports) in production group.
1) Delete the gemfile.lock file (from your project folder)
2) In the gemfile, remove gem sqlite3 or similar sqlite3 gem
3) Instead of that add following to the end of file:
group :development, :test do
gem 'sqlite3'
end
gem 'pg', group: :production`
Now, run the following commands in terminal:
bundle install
git add .
git commit
git push
git push heroku master
Although it was a silly mistake, It took me time to realize the same. Hope it helps someone.
Heroku's asset plugins no longer work since Rails 4 does not support plugins. You need to use Heroku's asset gems instead. Place this in your Gemfile:
group :production do
gem 'rails_12factor'
end
Answer found here: Heroku does NOT compile files under assets pipelines in Rails 4 worked for me
My issue was that I had my bower directory ignored in .gitignore.
So I either need to do bower install from my packages.json or check in my bower dir.
http://xseignard.github.io/2013/02/18/use-bower-with-heroku/
I chose to check in my bower dir for a quick solution right now.
Heroku does not like sqlite3, change gem 'sqlite3' with gem 'pg'
For M1 users,
bundle lock --add-platform x86_64-linux
to resolve the architecture conflict