Installing Ruby

benzittlau edited this page Mar 17, 2011 · 23 revisions

Follow the directions below to setup Ruby and Rails on your box. Once you're up and running you should go get introduced to Ruby!

Installing Ruby on Mac OS X

Mac OS X ships with Ruby pre-installed, however it's an older version that's out-dated for most people's uses. It's also missing some components neccesary to run Rails out of the box.

The best directions we've found for install Ruby and Rails are from the Pragmatic Programmer. You can also follow our directions below for the quick and dirty guide.

Installing Ruby with RVM

The Ruby Version Manager, or RVM, is by far the best way to install Ruby on your Apple computer. RVM allows you to quickly install multiple versions of Ruby on your computer and can be installed with one command:

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

If you run into problems consult their detailed RVM installation guide.

After you've installed RVM, you can install Ruby 1.9.2 with:

rvm install 1.9.2

This will download the source code for Ruby, compile and install it. Be prepared to wait a few minutes if you're using a slower computer. If you want to make this your default ruby when you open a new shell (rather than your Mac's older version), simply run:

rvm 1.9.2 --default

You can now switch in to ruby-1.9.2 and install the rails gem:

rvm 1.9.2
gem install rails

That's it, you're ready to go!

RVM Support

If you run into errors while installing RVM, first run a Google search. Chances are there others who have run into the same problem. If your Google searches don't resolve your problem, ask a Ruby friend. If that still leaves you high and dry, you can ask Wayne E Seguin (the creator of RVM). Visit http://rvm.beginrescueend.com/support/irc/ for more information. Wayne is a very friendly guy who is actually on IRC constantly and loves helping people install and use RVM. If your problem ends up being with the RVM source code, he will (usually) fix it and push up new source code to Git while he talks to you on RVM. Awesome.

Installing Ruby on Ubuntu Linux

Pragmatic Programmers come through again with some great directions for installing Ruby and Rails on Ubuntu.

The quick guide is:

sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline5-dev libsqlite3-dev
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
echo [[ -s \"\$HOME/.rvm/scripts/rvm\" ]] \&\& source \"\$HOME/.rvm/scripts/rvm\" >> ~/.bashrc
source ~/.bashrc
rvm install ree-1.8.7-2011.03

Installing Ruby on Windows

Installing Ruby on Windows used to be a challenge, however there are now two excellent options that make this process painless.

RubyInstaller.org (recommended)

The Rails Installer for Windows is a new project headed up by the folks at Engine Yard - particularly by Wayne E Seguin (the creator of RVM) and Dr. Nic. Rails Installer for Windows will get you quickly setup with:

  • Ruby 1.8.7-p334
  • Rails 3.0.4
  • Git 1.7.3.1
  • SQLite 3.7.3
  • DevKit

Download and follow the directions on their site to get started.

There seems to be issues with Rails Installer not delivering a certificate authority bundle for SSL. This leads to problems interacting with SSL websites in your Ruby code. You can fix this problem by following these instructions.

Update Rubygems and Rails Gem

The Ruby community often moves at a lightning pace, so it's very possible that your fresh Rails Installer installation is already a bit out-of-date. You can update your Rubygems to current by opening a command prompt and typing:

gem update --system

To update to the latest stable Rails gem, run:

gem update rails
gem cleanup

The gem cleanup will remove any old gems that have newer versions installed.

jRuby

As the name implies jRuby provides Ruby a home on top of the Java Runtime Environment. It's quick to install and we recommend you get the latest release with is 1.6.0.RC3. This doesn't include Rails, git or a database which will all need to be installed separately.

Note that one of the jRuby installers also includes Java if you don't have it already installed.

To run jRuby in Ruby 1.9 mode (the current default is to run in Ruby 1.8 mode), you can use the --1.9 flag like so:

jruby --1.9 -e 'puts "Hello, World!"'

Most of the Ruby commands should be run with jRuby's standalone script flag (-S) to ensure that you are not running the normal ruby interpreter.

Installing Rails

Simply:

jruby -S gem install rails