Thursday, September 13, 2012

Install Local (Edge) Rails 4.0 Beta and Create a New Rails App

Thanks to Dru Riley's post, Create a Rails 4.0 Beta Project, for leading me down the right road for this, although I was able to get it working without having to alter the Gemfile.

The following is what I did in OS X 10.7.4 with RVM installed. I also updated Homebrew right before I started. (Note: I also ran into a gist with some instructions for Windows from Aaron Breckenridge; I don't know if you need to do it that way for Windows or not.)

First I'm assuming you have a Rails git repo cloned locally:

mkdir ~/github
cd ~/github
git clone https://github.com/rails/rails.git
You may also have your own fork of Rails that you made in GitHub and could clone to mess with like:
mkdir ~/github
cd ~/github
git clone https://github.com/your_github_user/rails.git
and if you did fork it you might want to setup a remote so you can periodically 'git pull rails master' to get updates:
git remote add rails https://github.com/rails/rails.git
git pull rails master

Here's my hackish way to build Rails in its current state. First you really should be using RVM or something to keep the gems separate, otherwise you could seriously screw up any other environments. Create an .rvmrc file so that the new rails has its own gemset:

echo "rvm use ruby-1.9.3-p194@local_rails" > ~/github/rails/.rvmrc
Now back out of that directory if you are in it, and cd back into it (make sure you are really cd'ing and not aliasing cd to something else as some do) and enter "Y" to create the new gemset:
cd ~/github/rails
To ensure that worked, check with 'rvm gemset list'. If you don't already use Ruby 1.9.3, you need to install that first (follow the RVM instructions, then cd .. and cd rails again until this works.
rvm gemset list
That should show an arrowish looking thing pointed to rails.

Now for installing Rails. 'rake install' fails at the moment because it can't find the rails gem (it ends with "ERROR: Could not find a valid gem 'pkg/rails-4.0.0.beta.gem' (>= 0) in any repository"). Totally confused by that, but ignore that error and this works:

gem update bundler # or gem update
rake install
gem build rails.gemspec
gem install rails-*.gem
More fun ahead- you need a local version of journey 2.0.0 (or later):
cd ~/github
git clone git://github.com/rails/journey.git
cp ~/github/rails/.rvmrc ~/github/journey
cd ~/github/journey
Ensure you are still using the rails gemset:
rvm gemset list
Then create and install journey 2:
gem build journey.gemspec
gem install journey-*.gem
Nate Lunde-Berry reports that you need to do this with activerecord-deprecated_finders also (I didn't have to, but just in case):
cd ~/github
git clone git://github.com/rails/activerecord-deprecated_finders.git
cp ~/github/rails/.rvmrc ~/github/activerecord-deprecated_finders
cd ~/github/activerecord-deprecated_finders
Ensure you are still using the rails gemset:
rvm gemset list
Then create and install journey 2:
gem build activerecord-deprecated_finders.gemspec
gem install activerecord-deprecated_finders-*.gem
Now lets build an area for your Rails 4 spike projects to keep them away from your other projects:
mkdir ~/spike
Here is a 3-in-one that sets your RVM to use new rails, creates a spike app and adds an .rvmrc. Substitute your app name:
APP_NAME='my_new_app' && rvm use ruby-1.9.3-p194@local_rails --create && ruby ~/github/rails/railties/bin/rails new $APP_NAME --dev && echo "rvm use ruby-1.9.3-p194@$APP_NAME" > $APP_NAME/.rvmrc;
cd $APP_NAME
bundle install
rails s

6 comments:

Nate said...

Thanks. I had to repeat the process for journey with activerecord-deprecated_finders but this really helped me a lot.

Gary S. Weaver said...

Thanks, Nate! I updated the post with that info.

Stephen Murdoch said...

rake install does nothing, should that be something else perhaps?

Stephen Murdoch said...

rake install fails with 'cannot load such file -- sdoc'

Ori Pekelman said...

Probable cause: you complied ruby without ssl support so bundle install fails, simply change
source 'https://rubygems.org' to
source 'http://rubygems.org' in your Gemfile

breckenedge said...

Lol Google pointed me here as I'm trying to get Rails 4 running on my Mac. Thanks for the credit.