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 -.