Installing Ruby 2.0

I had a bit of an adventure this morning getting Ruby 2.0 installed on my mac with Mountain Lion, so I thought I’d share the tale with you in case it can help save you some time on doing the same. Up until now I’ve been developing my Rails apps with 1.9.3, but it was time to upgrade and experience all the new hotness of the latest Ruby. I had tried to install Ruby 2.0 before, but I had been stymied by an openssl error when building. Today was to day to get that sorted.

I’m using rbenv to manage the different Ruby versions on my machine, so the first step was to update ruby-build, which I have installed via homebrew, so that I could fetch and build the latest Ruby. Sadly, I had some weirdness with my homebrew installation that prevented me from getting the latest homebrew, which prevented me from getting the latest ruby-build, which prevented me from being able to install the latest Ruby (2.0.0-p247):

$ brew update
error: Your local changes to the following files would be overwritten by merge:

I was pretty sure I hadn’t changed anything in homebrew myself, and I found some guidance in the github issues list for homebrew that I should just blow away my local changes with a git reset, which didn’t initially work because apparently some permissions had changed in /usr/local:

$ cd /usr/local/Library
$ git reset --hard FETCH_HEAD
error: unable to unlink old '' (Permission denied)
error: unable to unlink old '' (Permission denied)
fatal: Could not reset index file to revision 'FETCH_HEAD'.

$ sudo chown -R `whoami` /usr/local
$ git stash && git clean -d -f
$ brew update

Now I was in business. Next up I upgraded ruby-build, and since I had already installed openssl via homebrew previously, I could use that while compiling:

$ brew upgrade ruby-build
$ env CONFIGURE_OPTS='--with-openssl-dir=/usr/local/opt/openssl' rbenv install 2.0.0-p247

Boom! Ruby 2.0 was finally installed. But then I hit a snag while trying to install gems for one of my Rails projects:

$ bundle
Could not verify the SSL certificate for
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about
OpenSSL certificates, see To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'.

That was an especially useful error message, since that link provided a tip on easily getting some updated ssl certificates:

$ brew install curl-ca-bundle

And that tells you to

$ export SSL_CERT_FILE=/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt

And now everything works. Woohoo!

Update - September, 2014: According to this issue, something has changed in homebrew that makes this change break things. So try leaving out that step.