1: Installing Rails 4 without breaking Rails 3

The first part of the Rails 4 tutorial is actually getting Rails 4 without messing up your existing Rails 3 install.  The other parts of this tutorial can be found at the index, or by hitting the tutorial menu above and selecting the Rails 4 tutorial option.

We’re going to use RVM to create a separate gemset for ruby 2.0.0, which should give us separation between our projects.

Review the documentation on RVM, and download and install RVM if you haven’t already got it.  If you didn’t already have RVM (many setups come with it standard) you probably want to be careful as you create the gemset for ruby 2.0.0, make sure you haven’t broken your old gemset(s).

First, ask RVM to install ruby 2.0.0 for you:

rvm install 2.0.0

Next, create the project directory, I’m calling mine league-tutorial-rails4, and if you call yours that it’ll match what you get if you clone the code from github:PaulL.  Go into that directory:

cd league-tutorial-rails4

And tell rvm that this project uses ruby 2.0.0:

rvm use 2.0.0

Following the instructions at , we install rails 4.0.0:

gem install rails --version 4.0.0 --no-ri --no-rdoc

Make sure you don’t use sudo, you want rvm to be managing this for you.  This should now have given you a gemset with rails 4 in it.

Next, go back up a directory, and ask rails to create the application over top of your directory:

cd ..
rails new league-tutorial-rails4

We’d like rvm to automatically change versions for us. Our research starts at stackoverflow, but ending up in the rvm documentation,  we learn that we used to use a .rvmrc file to control versions.  However, this file also allows arbitrary scripting, which makes it a security issue of you take it all the way to production.  Instead, we ask rvm to create a .ruby-version file for us, and optionally, a .ruby-gemset file.

rvm --ruby-version use 2.0.0

This should create a .ruby-version file, and whenever you come into the folder rvm should change to 2.0.0 for you automatically.  If you had a gemset (in the form 2.0.0@myGemset) then it would also have created a .ruby-gemset file for you.

If this isn’t working for you, now’s the time to sort it out, and it’s most likely due to your profile settings (some rvm-specific variables need to be set on login).  You may find that if you’ve only just installed rvm, that closing all your terminal sessions and reopening may fix it (i.e. the variables may have been added to your profile, but don’t take effect unless you either log in again, or source ~/.profile).

You can verify this is working by changing between your folders and issuing:

ruby --version
rails --version

It should be changing between the projects, and should be 2.0.0 / 4.0.0 for the tutorial.

Make sure you have everything working cleanly, and then move on to creating the application itself in the next tutorial step.


10 thoughts on “1: Installing Rails 4 without breaking Rails 3

  1. Pingback: Creating the base rails backend | technpol

  2. Pingback: AngularJS and Rails 4 CRUD application using ng-boilerplate and twitter bootstrap 3: Tutorial Index | technpol

  3. Pingback: Rails app for Angularjs, building the rails league application: part 1 | technpol

  4. Pingback: AngularJS and Rails CRUD application using ng-boilerplate and twitter bootstrap: Tutorial Index | technpol

  5. Pingback: AngularJS and Rails Tutorial: part 3 a basic list using $resource for a restful query from rails | technpol

  6. Pingback: AngularJS and Rails Tutorial: part 4 ngGrid and edit in a modal popup | technpol

  7. Pingback: AngularJS and Rails Tutorial: part 5 New and Delete, initial $resource error handling | technpol

  8. Pingback: AngularJS and Rails Tutorial: part 6 the team entity, grid filtering, links between pages | technpol

  9. Pingback: AngularJS and Rails Tutorial: part 7 form error handling, datepicker | technpol

  10. Pingback: AngularJS and Rails Tutorial: part 4.5 unit testing bootstrap modals with Karma | technpol

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s