In one of my current project, whenever I ran a rake task that did a net/http request it was causing segmentation faults.
$ /Users/cirish/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:678: [BUG] Segmentation fault
ruby 1.9.2 (2011-06-30 patchlevel 290) [i686-darwin10.8.0]
And it seems whenever I get a segmentation fault the first place I need to look is at OpenSSL. I’ve had similar problems with seg faults and openssl in the past, namely this OpenSSL Bus Error that I was getting on Ruby 1.8.7.
If you read that post you’ll see this happened because I use MacPorts and have OpenSSL installed through it, in addition to a local OS X version. To get Ruby to be happy, you have to point your Ruby install to the correct version at installation time. So remove the bad install
And reinstall
Which I forgot to do with my Ruby 1.9.2 install after upgrading OS X versions. That last bit about iconv isn’t directly related, but I have inconv package installed to RVM, you can read about that here RVM Iconv.
Also, this Phusion blog post REE 1-8-7-2011-03-released mentions problems with OpenSSL and MacPorts. Moral of the story… use HomeBrew? Dunno, but I’ll probably start using it when I upgrade my laptop.
{ 21 comments… read them below or add one }
For me the fix for this with an RVM version of ruby is to install it with the RVM OpenSSL package .In particular I used the following to install ruby 1.8.7-p174 .rvm package install iconv.rvm package install openssl.rvm install 1.8.7-p174 –with-openssl-dir HOME .rvm usr –with-iconv-dir rvm path usr…
Chris, thanks for posting this. After wading through a fair number of bug reports, your instructions were clear, concise and correct!
Your delete command is wrong. It should be:
$ rvm remove ruby-1.9.2
Yep, thanks for the catch, post updated.
Does this work with Homebrew? According to https://github.com/carlhuda/bundler/issues/1596 we need openssl 1.0, but it looks like Homebrew only has openssl 0.9.8r
Hey Tim, I’m not sure as I’m not currently using Homebrew. From the sound of that ticket, perhaps OpenSSL 1.0 is only a requirement of Ruby 1.9.3… But I’m not really sure.
No problem. I got it working with macports Thanks for the blog post!
Thanks for the tips. This is my clean install:
2
3
4
5
6
rvm pkg install iconv
rvm pkg install openssl
rvm install ruby-1.9.2 –with-openssl-dir=~/.rvm/usr –with-iconv-dir=~/.rvm/usr
rvm 1.9.2
ruby -ropenssl -e ‘p OpenSSL::Digest::Digest.new(“sha256″)’ # verify OpenSSL works
rvm install ruby-1.9.3-head -C –with-gcc=clang,–with-openssl-dir=~/.rvm/usr,–with-iconv-dir=~/.rvm/usr
the above worked for me. Thanks!
This works with Ruby 1.9.3 on Snow Leopard.
Thanks Mark!
This worked for me as well. Thanks!
On my Mac OS 10.7.3 I was able to install iconv and openssl but it wouldn’t run the command to install Ruby…
$ rvm install ruby-1.9.2 –with-openssl-dir=~/.rvm/usr –with-iconv-dir=~/.rvm/usr
Unrecognized command line argument(s): ‘–with-openssl-dir=~/.rvm/usr ‘ ( see: ‘rvm usage’ )
However, just installing the packages seems to have corrected the OpenSSL problem. If I just install Ruby normally without the options, then OpenSSL appears to work…
$ ruby -ropenssl -e ‘p OpenSSL::Digest::Digest.new(“sha256″)’ # verify OpenSSL works
#
The blogging software ate the last line but, the point was that the command ran without an error.
Thank you Mark. That saved me a lot of time and worked on Mac OSX 10.7.2
Thank you very much Irish!
Worked perfect for me!
Thank you for your solution, this also helped me.
I actually fixed this problem by downgrading OpenSSL. I had already installed the MacPorts one, but I built ruby 1.9.3-p125 without MacPorts and the segfault on https URL requests went away. See https://github.com/carlhuda/bundler/issues/1596
This is driving me crazy. I shouldn’t have to install rvm to get ruby to build correctly. There are so many rails developers on os x, I can’t believe this is not fixed yet.
You shouldn’t have to, you just need to make sure you’re pointing to the correct openssl when you install it. RVM is just for more convenience.
Thanks for the solution to this, really helpful post!
Best Post of the Year Award!!
Thanks you so much. I spent hours trying to figure this out.
{ 5 trackbacks }