Upgrading to Ruby 2.0 on Mountain Lion
Upgrading to Ruby 2.0 on Mountain Lion
Join the DZone community and get the full member experience.Join For Free
Planning to extract out a few microservices from your monolith? Read this free guide to learn the best practice before you get started.
Ruby 2.0 was released on 24th February to coincide with Ruby’s 20th anniversary. If you use RVM, and want to try out Rails 4.0 beta, then ideally you’ll want to be running Ruby 2.0. Here’s what I did to keep my development environment working the way I like it.
First, I’m running Macs with Mountain Lion (OS X 10.8.2), and I’m using the brilliant Ruby Version Manager (rvm) to manage my Rubies.
My scenario is this:
I want to be able to use Ruby 2.0 and Rails 4.0 beta. I do need to be able to run ruby-1.9.3-p392 too, because I still use Octopress for writing draft posts, and Octopress requires ruby-1.9.3-p392.
Here’s what I did:
I’m not sure if this step is entirely necessary, but I did it anyway with:
rvm get stable
I mean RubyGems itself, the actual gems get dealt with in a moment:
gem update --system
That will upgrade RubyGems to version 2.0.0.
Then I ran a generic gem update:
Making sure we are still raring to brew…
I use Homebrew to avoid all the dependency nightmares Mac users might otherwise be faced with. First, I did an update:
Then, I ran the doctor to make sure all was well:
You should get:
Your system is raring to brew.
If you don’t, just follow the advice you are offered by the doctor. Really. I have never experienced a situation where the advice is wrong/doesn’t work. And if you are going to work with Ruby, you need Homebrew on your Mac.
I’m not a fan of generalisations, and I realise that last par might be one. However, that is what my experience has been. If yours has been different, please comment below.
Try not to let your eyes glaze over – libyaml is required
I’m not a fan of endless geek/nerd discussions about libraries/algorithms and other such technical matters either. I just want to build web apps. Research tells me that libyaml is required because Ruby 2.0.0 deprecated syck in favour of psych. If you’re interested, there is some explanation available here, and you can read about yaml here. Rails uses yaml, and so does Ruby 2.0 is the bottom line, so:
brew install libyaml
You need OpenSSL too
Apparently, there is a compatibility problem with your Mac’s version of OpenSSL and the version you need for Ruby. It’s solved by doing:
rvm pkg install openssl
Which will finish with this message:
Please note that it's required to reinstall all rubies: rvm reinstall all --force
So do it.
And now for Ruby 2.0
So far, so good. Now we can install Ruby 2.0:
rvm install 2.0.0
Go and put the kettle on, this will take a while…
It should end with:
Install of ruby-2.0.0-p0 - #complete
You might as well set it as the default Ruby:
rvm use 2.0.0 --default
Upgrading to ruby-1.9.3-p392
As I mentioned earlier, Octopress still needs ruby-1.9.3-p392. Your blog will have it’s own gemset, which is why you get a message like this:
Do you wish to trust this .rvmrc file? (/Users/you/yourblog/.rvmrc) y[es], n[o], v[iew], c[ancel]> y
cd into your blog directory. Let’s upgrade then:
rvm upgrade ruby-1.9.3-p362 ruby-1.9.3-p392
Time for another brew, this will take a while…
You’ll eventually be asked this question:
Are you sure you wish to MOVE gems from ruby-1.9.3-p362 to ruby-1.9.3-p392?
y not with any great technical insight, it just seemed like the logical thing to do. I did the same for the next set of questions too:
Do you wish to move over aliases? (Y/n): y Do you wish to move over wrappers? (Y/n): y Do you also wish to completely remove ruby-1.9.3-p362 (inc. archive)? (Y/n): y
Then, I got:
Successfully migrated ruby-1.9.3-p362 to ruby-1.9.3-p392 Upgrade complete!
And began writing this post. It seems to have worked just fine. I can do a:
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
Apart from when I’m in my Octopress directory. If I run it there, I get:
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.2.0]
Great, everything works!
Now I have the latest Ruby available globally on my Mac, running Mountain Lion. I also have ruby 1.9.3p392 installed so that I can continue to use Octopress. These steps are what worked for me, if you’ve discovered something different, or a problem, please share below.
Published at DZone with permission of Andy Hawthorne , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.