Ruby on Rails
GettingStartedWithRails

1. Make sure you have Ruby installed

Rails 1.2.3 works with Ruby 1.8.6. You may need to update/download Ruby before continuing with your endeavors.

CentOS See RailsOnCentOS Portal
Debian See RailsOnDebian.
Ubuntu See RailsOnUbuntu
Ubuntu Also see TurnKeyRails – an Ubuntu-based installable Live CD appliance created by TurnKey Linux
Gentoo emerge rails or see the Gentoo Wiki entry
Fedora Core See RailsOnFedora. If you do not install Ruby from source, be sure to install irb, the ruby interactive shell, as well ( yum install irb ). Otherwise, Breakpoint will not work properly. FC package for irb now called ruby-irb, so “yum install ruby-irb.i386”
Fedora Core 3 You can also use RailsOnSpike . It is an integrated LAMP stack + Ruby on Rails crafted by SpikeSource.
Fedora Core 6 See RailsOnFedora6.
Redhat 9 See Ruby and Rails on Red Hat Linux 9 (and maybe Fast CGI and Apache2 for Red Hat Linux 9).
FreeBSD See RailsOnFreeBSD.
OpenBSD See RailsOnOpenBSD.
OSX See HowtoInstallOnMacOSX.
Solaris See Cool Stack. Download the CSKruby package.
Windows See RailsOnWindows
Rails Live CD appliance See HowToInstallWithRailsLiveCD

After installing Ruby, be sure to check your version by executing ‘ruby -v’. In particular, a lot of Mac OS X users get bitten by this, as Ruby 1.6, which is bundled by Apple, shadows the 1.8 installation. See SettingYourPath.

(NB: Ubuntu/Debian: openssl may give ‘not found’ error. Then do:
cd ruby_src_dir/ext/openssl
ruby extconf.rb
make
make install

http://www.semergence.com/2007/03/15/installing-openssl-support-for-ruby-on-ubuntu/

2. Get Ruby on Rails

To get Ruby on Rails using Ruby Gems, see GemRails.

gem update
gem install rails --include-dependencies

(Be patient, this might take awhile. The —include-dependencies answers “yes” to any queries of whether to download other dependent projects, like rDoc.)

3. Make a Rails application

When you’re ready, Rails will make all the directories you need to get started and set some permissions for you to boot. All you’ve got to do, now that Rails is installed, is point the rails command at wherever you wish to create your application (this should not be a place your Web server can access directly):

rails /usr/myapp
ln -s /usr/myapp/public /var/www/myapp

The public directories in the next step are located in your new application directory.

4. Using the proper path for Ruby (the she-bang line!)

Rails is pre-configured to reference Ruby using /usr/bin/env ruby, which should work for most installations.

If for some reason /usr/bin/env ruby doesn’t work for you, or gives you the wrong ruby interpretter, then:

  1. change your path to reference the correct ruby
  2. At the beginning of public/dispatch.cgi, public/dispatch.rb, public/dispatch.fcgi, script/breakpointer, script/console, script/generate, and script/server, change this line:
#!/usr/bin/env ruby

There are some command-line scripts to modify the necessary files, see ShebangChangeScripts.

5. Making sure Apache is set up

Note: if you are okay with running rails under WEBrick for now, skip to section 7

Apache needs to be configured for running CGI files in order for Rails to run. So make sure you have AddHandler cgi-script .cgi somewhere in your Apache config file.

  1. Set up Apache for the Rails application. If you plan to run your application at the DocumentRoot of a virtual host (perhaps as your entire web site), see “Example for Apache conf” below. If you would like it to live elsewhere see
    HowToSetTheBaseURLsOfYourRailsApps.
  2. Go to rails/ (or whatever is your ServerName) and check that you get the “Congratulations, you’re on Rails!” screen
  3. Follow the guidelines on the “Congratulations, you’re on Rails!” screen

Example for Apache conf

In the Apache configuration given, replace the /path/application with the full path to the rails directory unpacked with the tar.gz, and be sure to append the public or log directory on where noted below. I also had to turn on CGI and set some access requirements as shown below. The AllowOverride line is important – internally, Rails uses some redirection that takes place in a .htaccess file located in the public folder. (Suse 9.1’s Apache is locked down fairly tight.)

Rails also requires the mod_rewrite module.

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule env_module modules/mod_env.so

<VirtualHost *:80>
   SetEnv RAILS_ENV development
   ServerName rails
   DocumentRoot /path/application/public/
   ErrorLog /path/application/log/apache.log

   <Directory /path/application/public/>
      Options ExecCGI FollowSymLinks
      AddHandler cgi-script .cgi
      AllowOverride all
      Order allow,deny
      Allow from all
   </Directory>
</VirtualHost>

Also, make sure that apache has write permissions to the /path/application/tmp directory.

6. Checking the logs for clues

Rails will report errors from Apache in log/apache.log and errors from the Ruby code in log/development.log. If you’re having a problem, do have a look at what these logs are saying.

On Unix and Mac OS X you may run tail -f log/development.log in a separate terminal to monitor your application’s execution.

7. Tutorials

After you get a basic idea of what’s going on using the tutorials above we recommend having a look at the OpenSourceProjects section. Especially if you are the type who learns best from other people’s source.

8. Getting real-time help

Are you having problems getting the basics running? Come ask the Railers on IRC in room #rubyonrails (IRC|How to get on IRC).


Translations: