2

I've got a Rails 4.0.2 app that I'm upgrading to Rails 4.2. I've followed the migration guide exactly. I've run the migration rake task at each step and I also ran bundle / bundle update to update my dependencies. As part of the process I also had to upgrade from Ruby 2.0.0 to 2.3.0.

When I try to start my rails server I get the following output:

/Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/key_generator.rb:2:in `require': cannot load such file -- openssl (LoadError)
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/key_generator.rb:2:in `<top (required)>'
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application.rb:5:in `require'
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application.rb:5:in `<top (required)>'
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails.rb:11:in `require'
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails.rb:11:in `<top (required)>'
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/commands/server.rb:4:in `require'
from /Users/ACIDSTEALTH/.gem/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/commands/server.rb:4:in `<top (required)>'
from /Users/ACIDSTEALTH/Dropbox/Work/firmplay/config/boot.rb:5:in `require'
from /Users/ACIDSTEALTH/Dropbox/Work/firmplay/config/boot.rb:5:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'

I've tried the following, all without any success:

  1. I ran brew install openssl. Installed openssl. No dice.
  2. Ran brew update and brew doctor. This led me through a whole cycle of uninstalling and reinstalling brew. Got brew reinstalled along with openssl. Still no luck. Same error.
  3. Tried downgrading the app to Ruby 2.0 again, but that raised some dependency issues in the Gemfile, so it's not an option.
  4. Tried gem install openssl, which failed with:

    ERROR: While executing gem ... (Gem::Exception) Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

I've been banging my head on the keyboard all day on this. What limited resources I've found on this issue are all specially tailored to users who use rvm. I tried installing rvm but that led to another slew of problems, forcing me to ultimately remove rvm and all traces of it from my system.

My setup: OS 10.11.3 Xcode (latest release) iTerm2 /w ZSH Homebrew (latest) Chruby and ruby-install for managing rubies Migrating from Rails 4.0.2 on Ruby 2.0.0 to Rails 4.2.5 on Ruby 2.3.0.

Update

I made some progress on resolving this, though I must admit I feel quite clueless about what the source of the problem was to begin with. I ran ruby-install ruby-2.3.0 — --with-openssl-dir=/usr/local to recompile Ruby. Restarted my shell and this time I was able to reinstall openssl, but I had to do sudo gem install openssl. From here I was finally able to launch my rails server. I'm still really confused about what happened here.

Daniel Bonnell
  • 4,817
  • 9
  • 48
  • 88
  • How about upgrading Ruby first, testing all is good, then upgrading Rails? – Eric Platon Feb 25 '16 at 20:29
  • Not sure what you mean by that. I upgraded to 2.3.0 and I can confirm that it works by opening up irb.... – Daniel Bonnell Feb 25 '16 at 20:45
  • 1
    Maybe try recompiling Ruby. You may have compiled it before you had openssl installed. – Adam Sheehan Feb 25 '16 at 20:50
  • I deleted Ruby and ran `ruby-install -- --with-openssl-dir=/usr/include` based off advice from [this issue](https://github.com/postmodern/ruby-install/issues/194) with ruby-install. Still didn't work. – Daniel Bonnell Feb 25 '16 at 20:55
  • I also tried following the steps outlined here in regards to the error with requiring openssl when installing a gem. Didn't work. https://gist.github.com/luislavena/f064211759ee0f806c88 – Daniel Bonnell Feb 25 '16 at 21:09
  • Also tried using non-secure rubygems to install openssl, like so: `gem source -r https://rubygems.org/` and then `gem source -a http://rubygems.org/` – Daniel Bonnell Feb 25 '16 at 21:13

1 Answers1

0

Just posting for the records.

Doing double upgrades can be pretty complicated. In general, it is easier to proceed in stage, and check that there is no regression before moving to the next.

The original upgrade method was basically to upgrade Rails, then, as Rails complained about the Ruby version, to upgrade Ruby. That's a recipe for hard life. That's where we usually need to start over.

Upgrading a language version can be pretty hard. Since Ruby 2.0 things have gone so much better that it is often a no brainer, but still, better be cautious. It can happen that your code works with one version and breaks somewhere with the next. That's where a good test suite helps, as well as more evolved validation or verification tools. All that may sound overkill, but consider that things like Array#to_h appeared in Ruby 2.1, and quite a few gems may already use it...

Once the target Ruby version runs the code without regression (as much as time allows to check), then upgrading the project core library (here, Rails), is much easier. The scope of possible problems is suddenly smaller.

Now you had to go as far as restarting your shell to get proper "links" to the OpenSSL library. Hard to say what happened now, but it may be a permission problem, or a big in the library installer. Again here, many things happen at the same time, and it is often much easier to reduce the scope and start over.

Eric Platon
  • 9,819
  • 6
  • 41
  • 48