Ruby on Rails
GettingStartedWithRails (Version #574)


Ubuntu See the Ubuntu Wiki entry or this old document and this.
Gentoo See the Gentoo Wiki entry or this older document.
FreeBSD See RailsOnFreeBSD.
OpenBSD See RailsOnOpenBSD.
OSX See RailsOnOsx. You can use the installer or DarwinPorts.
Windows See RailsOnWindows
Rails Live CD See HowToInstallWithRailsLiveCD
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.
Fedora Core 3 You can also use Rails on Spike . 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).

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.


2. Get Ruby on Rails


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


gem update
gem install rails 

(Be patient, this might take awhile.)


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 interpreter, 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
    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:



Ubuntu See the Ubuntu Wiki entry or this old document and this.
Gentoo See the Gentoo Wiki entry or this older document.
FreeBSD See RailsOnFreeBSD.
OpenBSD See RailsOnOpenBSD.
OSX See RailsOnOsx. You can use the installer or DarwinPorts.
Windows See RailsOnWindows
Rails Live CD See HowToInstallWithRailsLiveCD
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.
Fedora Core 3 You can also use Rails on Spike . 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).

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.


2. Get Ruby on Rails


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


gem update
gem install rails 

(Be patient, this might take awhile.)


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 interpreter, 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
    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:


Created on November 18, 2006 11:34 by RL (210.84.61.194)