Fixing "OpenSSL certificate verify failed" Error with Ruby on OSX Mountain Lion

I spent days trying to correct an OpenSSL issue with the excellent Rails Composer utility and thought I would post the solution here in case it would help someone having the same problem.
This problem started when I replaced my MacBook Pro hard disk drive with an SSD drive and used the occasion to do a clean install of MacOSX Mountain Lion. This allowed me to shed dozens of GB of cruft, and rock a very speedy MBP to boot; but also introduced this infuriating error which would rear its ugly head every time I tried to use Rails Composer as follows:

$ rails new myapp -m
Which consistently led to this error message:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
The problem and its cause are clearly explained by Daniel Kehoe here: 
Daniel also generously provides several solutions. I tried them all as well as several others suggested by other generous netizens. Unfortunately, none of these suggestions worked for me.
This morning I had what turned out to be a very helpful epiphany: the problem began after I reinstalled ruby and rails, so it's not a Mountain Lion problem as everything was working fine on Mountain Lion before I swapped my HD for an SSD. So, I reasoned that the issue was related to differences between my new ruby and rails installation and the old one.
The specific difference was that this time I used RailsInstaller to reinstall ruby and rails, while I had previously used a combination of ​Xcode CLT, Homebrew, and RVM.
To test my hypothesis I used the RailsInstaller/Uninstaller to remove everything that RailsInstaller added except the GCC compiler, then used the following recipe to reinstall ruby and rails (modified from -- Thanks wheelhouse CMS!):

  1. Install Homebrew: $ ruby <(curl -fsSkL
  2. Run 'Brew Doctor' to confirm proper installation:
    • In my case, 'Brew Doctor' informed me that I had the wrong GCC compiler version
    • This was installed by RailsInstaller but I told the uninstaller to leave it when I uninstalled RailsInstaller
    • This may have contributed to the failure of some of the other options from resolving the problem 
  3. Install Correct Command Line Tool for OSX 10.8: Use Xcode Preferences/Download/Install option 
  4. Install RVM:
    • $ curl -L | bash -s stable

    • Close/reopen Terminal then execute: $ rvm install 1.9.3

    • Confirm proper installation using:
      • $ rails -v 
      • This should produce: "ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]"
  5. Install Rails:
    • $ gem install rails
    • Confirm proper installation using:
      • $ rails -v
      • This should produce "Rails 3.2.8" or whatever the latest version of Rails at this time
  6. Verify problem has been resolved:
    • $ rails new myapp -m

    • This should initiate the rails composed service without error.

This recipe solved a frustrating problem for me that has also affected many others. I hope it helps you. 

Add new comment