Petros Amiridis My Internet home.

Segmentation fault with sqlite3 and Rails console on macOS Sierra

I was trying to demonstrate some basic Active Record commands using the Rails console yesterday during the MSc Class I am teaching. I fired up the console as usual bin/rails console, and tried to create an instance of one of the models I had created, and got this:

Loading development environment (Rails 5.0.0.1)
irb(main):001:0> Task.new
.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:27: [BUG] Segmentation fault at 0x00000000000110

I couldn’t figure out what the problem was at that point. But today, I searched for a solution.

Here is what I have found so far:

  • That’s related to macOS Sierra and the default sqlite installation
  • The default sqlite does not play well with processes that fork it in memory
  • The solution is to install sqlite3 using brew
  • Uninstall any sqlite3 gems and install them again to pick up the new version

For my particular situation (I am using rbenv, bunlder, Ruby 2.3.1, and Rails 5.0.0.1) here is what worked:

brew update
brew install sqlite3 # At this point I restarted my terminal
cd into-my-rails-project-that-had-the-problem
gem uninstall sqlite3
bundle update

and it worked:

Loading development environment (Rails 5.0.0.1)
irb(main):001:0> Task.new
=> #<Task id: nil, title: nil, created_at: nil, updated_at: nil>
irb(main):002:0>

If my post saved your bacon, please don’t hesitate to let me know. :)