Living on the edge (OSX ML) or How to install Ruby 2.0rc1 and Rails 4.0pre

Mario ChavezNov 27, 2012

Setup an environment for ruby/rails edge is not as simple as it seems, there are a few steps that needs to be taken care for first.

I'll assume that you are familiar with the set of tools that I'm going to use to generate my edge dev environment, also I'm assuming that you have latest XCode version installed, as well the Command Line Tools.

I will be using HomeBrew to install all dependencies in isolation from OSX System. Also I'll user rbenv and ruby-build, becase both simplifies the process to setup my environment and mostly because I'm used to them.

OpenSSL

OpenSSL version include on Mountain Lion seems to be not compatible with Ruby 2.0. Here we are going to use HomeBrew to ease the installation of a compatible OpenSSL. Actually the step is pretty simple:

$ brew install openssl

After a few minutes - will depend on you Mac -, HomeBrew should finish and means that we are ready to install Ruby 2.0 rc1 - which is the available version at the time that I'm writing this guide -.

Ruby 2.0 rc1

Since we are using ruby-build and rbenv to build/install ruby, means that we can have an isolated environment to try it and then we can switch back to the Ruby version that we use mostly to work.

In order to get the option to install Ruby 2.0 rc1 from ruby-build we should update it from it's git repository - I assume that you already know how to do this -.

Now before actually start install Ruby 2.0 we need to export a two varibles, the first one is just tell to compilation process where to find OpenSSL:

$ export CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl`

The second variable is just to instruct rbenv to use clang compiler instead llvm-gcc.

$ export CC=clang

Now we are ready to install Ruby 2.0, this process will take a few minutes, so for now just execute the following line, sit back and relax:

$ rbenv install 2.0.0-rc1

After installtion process finish, you can try Ruby 2.0 with rbenv as follow:

$ rbenv shell 2.0.0-rc1
$ ruby --version

Rails 4.0

Installing Ruby 2.0 was actually a breeze, Rails unfortunetly will not be that easy, but also will not be incredible hard, it just needs a bit more of work.

The first thing that we need is to clone Rails repository into your machine, this is as simple as:

$ git clone git://github.com/rails/rails.git

Next we are going to have to install bundler pre since is the version that will work with Rails from trunk:

$ gem install bundler --pre

Once we have our local copy, navigate to the Rails source code and ejecute bundler like:

$ bundle install

This will clone additional dependencies need it by Rails 4.0.

Now here is where it comes the tricky part, we will not be able to use the Rails command to generate a new Rails 4.0 application, or at least not yet.

Let's create a new directory for your new application, manually. Inside of your directory execute:

$ bundle init

This command will create a new/empty Gemfile for you - I do assume that you installed bundle before for Ruby 2.0 -.

Our next task will be to add the following gems into our Gemfile:

gem 'rails',     github: 'rails/rails'
gem 'journey',   github: 'rails/journey'
gem 'arel',      github: 'rails/arel'
gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders'

We do save the Gemfile and execute bundle to resolve these dependencies.

$ bundle

After bundle finish, we are ready to bootstrap our application with Rails.

$ bundle exec rails new . --edge

At somepoint you will be asked to resolve a conflict due to Gemfile already being in our application and the rails new command trying to create a new one; just response yes to replace the file.

If you get to this point then it means that you have a brand new Rails 4.0 application, we can try it executing the server and pointing our browser to http://127.0.0.1:3000

Experiment

At this point you are ready to experiment at try by yourself all the goodies that Ruby 2.0 and Rails 4.0 brings to your development experience.

blog comments powered byDisqus