Ruby 2.x + Rails 4 in Ubuntu 14.04

posted in: HOWTO | 0

This a modernized update to a previous post I wrote on here, about doing Ruby 1.9 & Rails 3.

There are two ways you can go with Ruby, right now. Canonical is finally starting to get with the program with Ruby versions, and there is a Ruby 2.0 package, though that is lagging slightly on minor versions. Here’s a comparison of my RVM version and the Universe version.

Packages are nice, and a safe way to go. If you want to keep things simple and don’t mind being a little bit behind the curve, just stick with the package.

But since this is a blog, and you’re a reader and don’t have to make tough decisions, LET’S GET CRAZY AND DO RVM! I have heard that “rbenv” is the new hotness, though I have not yet used it. RVM still works and works well, so I’m going to cover that, here.

Getting started with RVM is pretty simple. There’s a way to do Ruby/Rails installation automatically (using the “–ruby” and “–rails” flags), but let’s do it step-by-step to make it a little less magical. Start out by installing RVM:

This will do stuff. It doesn’t take long. The second line will append the RVM activation script into your .bash_profile, so that it is available in your Term session. After that, you will either need to do [cc]source ~/.bashr_profile[/cc], or just close the Terminal and open a new session. You should be able to do this, now:

Now you can install one (OR MORE!) Ruby versions. Install all the ones you want, you can switch between them easily enough. For this example, we’re just going to install the latest Ruby, “ruby-head”:

Whatever other Rubies you want to install, you can switch with a simple rvm use RUBY-VER, where “RUBY-VER” is the item in the list (ie. ruby-2.1-head).

If you’re having issues here, check out the debugging guide on RVM’s main site.

RubyGems will handle all the heavy lifting from here on out. The RVM installation should include the RubyGems installation by default. If it doesn’t, check the RVM RubyGems guide.

Let’s install Rails 4.

One thing we can do now, with new Rails hotness, is to specify which version of Ruby we want right in the Gemfile. This will signal to RVM to switch to the correct Ruby version as soon as we cd into that App. Within APPNAME, edit your Gemfile and add this to the very top:

Now check it out:


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.