Using Rails 3.X with Heroku

A quick note from experience: using either Rails 3.0 or 3.1, I kept getting this error (issue #1376 at github):

$ git push heroku master
[…]
Installing ruby_core_source (0.1.5)

Installing linecache19 (0.5.12) 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/lib/ruby/1.9.1/fileutils.rb:243:inmkdir’: Read-only file system – /usr/local/include/ruby-1.9.1/ruby-1.9.2-p180 (Errno::EROFS)
from /usr/local/lib/ruby/1.9.1/fileutils.rb:243:in fu_mkdir'

Aha. The problem is in linecache19, and the explanation given by dpiddy in issue #1356 is spot on:

linecache at least with 1.9 needs the full ruby source/headers, not just what gets installed normally for building extensions. To aid in getting the necessary stuff, there’s the ruby_core_source gem which is used from linecache’s extconf.rb. ruby_core_source tries to fetch the appropriate ruby source distribution and move things from it under Config::CONFIG["rubyhdrdir"]. If that’s not somewhere you can write to, it’ll break.

You see the failure when installing linecache19 itself because installing ruby_core_source doesn’t actually do anything, it only does something when used from linecache’s extconf.rb.

The best way to avoid this problem is to put linecache (probably really ruby-debug) in a test/development group and pass --without development test or --deployment to bundle install on the server side.

So, to fix, make sure ruby-debug is specified in the Gemfile as follows (I like to use sqlite3 for local dev, but must use Postgres on Heroku):

group :development, :test do
  gem ‘ruby-debug19’, :require => ‘ruby-debug’
  gem ‘sqlite3-ruby’, :require => ‘sqlite3’
end

When you deploy to Heroku, Bundler will be run automatically as long as a Gemfile is present. If you check in your Gemfile.lock, Heroku will run `bundle install –deployment`. If you want to exclude certain groups using the –without option, you need to use `heroku config`. So, to make sure we don’t require the gems in development or test mode, set the app’s environment variable BUNDLE_WITHOUT as so:

$ heroku config:add BUNDLE_WITHOUT=”test development” –app app_name

Presto, Bob’s your uncle.

Advertisements
Leave a comment

1 Comment

  1. Hello,I’m still getting the same error even after the required configuration. Do you have any other suggestions? Thanks.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: