Ruby on Rails stack on Mac OSX keeps crashing while RVM looks ok (both 10.68 and 10.7). A fix.

I recently spent some time struggling with an annoying problem with a Ruby on Rails app that just kept crashing. My environment is(was) Mac OSX Snow 10.6.8.

How I fixed it

  • uninstall the entire stack: rails, bundler and all dependencies, gem and rvm itself,
  • change my system path settings (sudo vi “/etc/paths”, put “/usr/local/bin” on top)
  • restart the machine, verify that in my path “/usr/local/bin” comes before “/usr/bin”
  • re-install rvm, ruby 1.9.2, gem, bundler
  • verify “which ruby”, “which gem”, “which bundle”, they should all show the rubies path “~/.rvm/…rubies/…”
  • install rails, redo “bundle install” in the project folder

The problem

I was having troubles getting a ruby in rails application running. This same app had been running perfectly fine before, I didn’t touch the code and others didn’t seem to have any problems running it. So it had to be something with my environment. The main change that I did was to have migrated from Ruby 1.8.7 to Ruby 1.9.2. But everyone had done that too, the app had been nicely running on 1.8.7 for me too, but not on Ruby 1.9.2. Why was this happening? Why was I the only one experiencing this problem?

Clues that led to my approach

After some googling and reading up a few blog posts, I came across this post by Yehuda Katz. I followed Yehuda’s recommendations, but that didn’t fix my issue. He’d touched upon one thing that I was sure was going to be a good lead: some gems could have been compiled with the wrong version of Ruby or native libraries. That had to be it, but where, which gems? I thought if a quick reinstall didn’t do it, something must be seriously broken. As I started removing and reinstalling the gems one by one, I kept checking the search paths, that’s how I found out that it was consistently not what I was expecting, some gems were found on /usr/bin while others were found under /usr/local/bin or in the rubies (rvm).

The only way to stop this, for me, was to remove it all, force my system to search /usr/local/bin. So I cleaned my env, adjusted the file /etc/paths to search “/usr/local/bin” before other paths.

What I’ve learned here is, as Yehuda puts it, “check your assumptions first” is probably even stronger for the DRY Ruby on Rails like environments than say Java or .NET environments. Indeed it is too tempting to think that once you’ve installed rvm, the ruby on rails stack and some nifty little gems, all following some quickly assembled and even quicker read blog postings, that everything would be fine from there. And that’s the wrong assumption that one needs to challenge.

Installing rvm, instructing it to default to another ruby version is not all there is to it. One needs to ensure that the entire stack has a consistent chain of dependencies, it’s better to do it at install time when installing anything new, and running things (to check that no assumption was quietly falsified unbeknownst to you).