RVM (Ruby Version Manager) is a great tool that lets you install multiple versions of Ruby, Gems (Rails, etc.) all inside your home directory, so that it lives only within your user’s account and does not affect any system files at all. You can also create gemsets to maintain separate repositories of gems for different applications.
NOTE: You should never run any of these RVM related commands as sudo. All of these files will live in your home directory and should not be owned by root or any other user. If you sudo any of these commands, you will create lots of permission problems that will haunt you in the future.
Install RVM
To start us off, let’s install RVM. The official installation instructions have you run a shell script directly off their website. I was a little sketchy about this at first, but it makes the installation so ridiculously simple that I didn’t care.
Install RVM
$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
After the install is completed, you’ll need to source your .bashrc/profile/etc. file to bootstrap the RVM system (the exact file it was added to is shown in the instructions output by the installer). Or you can just open a new terminal.
Load RVM system
$ . ~/.bash_profile
Installing some prereqs
Depending on what Linux/UNIX flavor you’re using, you might need some additional packages before moving on (namely OpenSSL and iconv). Let’s install those now:
$ rvm pkg install openssl $ rvm pkg install iconv
Install Ruby
There’s a good chance you already have Ruby installed on your OS, however, it will be the system-wide version in /usr/local or somewhere similar:
Check Ruby Install
$ which ruby /usr/local/bin/ruby $ ruby -v ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-linux], MBARI 0x8770, Ruby Enterprise Edition 2010.02
Let’s install Ruby 1.9.3 now:
$ rvm install 1.9.3 -C --with-openssl-dir=$HOME/.rvm/usr,--with-iconv-dir=$HOME/.rvm/usr
This step will take some time as it actually downloads the Ruby source, configures it and compiles it. When it’s done installing, we can set ruby 1.9.3 as the default version by running:
$ rvm use 1.9.3 --default
Install Rails
Now that Ruby 1.9.3 is fully installed, we can go ahead and install Rails 3.2 using RubyGems. For speed we will disable documentation:
$ gem install rails --no-rdoc --no-ri
Create a Rails App
We should have everything installed that we need to get started with an actual Rails app.
Create new app
$ rails new helloworld
Creating a new Rails app will create the skeleton folder structure for you, start off with a basic gem set (located in Gemfile), and then run bundle install for you. The bundle install command installs all dependent gems from your Gemfile in your gem repository.
Let’s actually make some changes to your new Rails app and test it out.
Create index Controller
$ cd helloworld $ rails generate controller index $ vi app/controllers/index_controller.rb
Add the index action
class IndexController < ApplicationController
def index
@hello = 'World'
end
end
Add index view template
$ vi app/views/index/index.html.erb
<h1>Hello <%= @hello %>!</h1>
Start the Rails server
For development purposes, most developers just use the built-in Rails server. This can be executed by calling rails server (or rails s). This runs a local server that will listen on port 3000.
If you try running rails s now, you will likely get an error complaining about the lack of a JavaScript runtime. Starting in Rails 3.1, a new asset pipeline is being employed. This pipeline adds features like automatically minifying JS/CSS as well as compiling CoffeeScript or SASS/LESS. In order for your Rails server to run, it needs a JS runtime to execute JavaScript within Ruby. Let’s install therubyracer to make rails s happy.
Install therubyracer gem
Open the Gemfile for your Rails app and gem 'therubyracer' anywhere in this file. After saving the Gemfile, let’s reinstall our gems with the bundler.
$ bundle install
This will install therubyracer gem for us. Now try executing rails s again, and you should have a running Rails app. Open the app in your browser: http://localhost:3000/
Clean Up App
The default Rails app includes a placeholder index.html file. To finalize our setup, let’s remove that file and create our default route.
Remove index.html file
$ rm public/index.html $ vi config/routes.rb
config/routes.rb
root :to => 'index#index'
All done
You should be done now. If you refresh your browser, you should see Hello World!








2 Responses to “Installing Rails 3.2 with RVM”
For some other tips on installing Rails 3.2, here’s a useful article:
Read This Before Installing Rails 3.2
Thanks for the comment Daniel! Great link! Cheers!