- Rails 2.1 Sends Emails
- Rails 2.1 Uploads Files
- Rails 2.1 and AJAX
- Rails 2.1 Scaffolding
- Rails 2.1 Layouts
- Rails 2.1 Views
- Rails 2.1 Controllers
- Rails 2.1 Migrations
- Rails 2.1 Active Records
- Rails 2.1 Database Setup
- Rails 2.1 Examples
- Rails 2.1 Dir Structure
- Rails 2.1 Framework
- Rails 2.1 Installation
- Rails 2.1 Introduction
- Rails 2.1 Home
Advanced Ruby on Rails 2.1
- Rails 2.1 Tips & Tricks
- Rails 2.1 Unit Testing
- Rails 2.1 Routes System
- Rails 2.1 Error Handling
- Rails 2.1 Basic HTTP Auth
- Rails 2.1 RMagick Guide
Quick Reference Guide
Ruby on Rails 2.1 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Ruby on Rails 2.1 - Installation
To develop a web apppcation using Ruby on Rails Framework, you would need to install the following software −
Ruby
The Rails framework
A Web Server
A Database System
We assume that you already have installed a Web Server and Database System on your computer. You can always use the WEBrick Web Server, which comes with standard installation of Ruby. Most sites, however, use Apache or pghtTPD in production.
Rails works with many database systems, including MySQL, PostgreSQL, SQLite, Oracle, DB2 and SQL Server. Please refer to a corresponding Database System Setup manual to setup your database.
Let s look at the installation instructions for Rails Framework on Windows, Mac OS X, and Linux.
Rails Installation on Windows
First, let s check to see if you already have Ruby installed. Bring up a command prompt and type C:> ruby -v. If Ruby responds, and if it shows a version number at or above 1.8.6, then type C:> gem --version. If you don t get an error, skip to step 3. Otherwise, we ll do a fresh installation for Ruby.
If Ruby is not installed, then download an installation package from rubyinstaller.rubyforge.org.Follow the download pnk, and run the resulting installer. This is an exe pke ruby186-25.exe and will be installed in a single cpck. You may as well install everything. It s a very small package, and you ll get RubyGems as well along with this package.
With RubyGems loaded, you can install all of Rails and its dependencies through the command pne −
C:> gem install rails --include-dependencies
The above command may take some time to install all dependencies. Make sure you are connected to the internet while instalpng gems dependencies.
Congratulations! You are now on Rails over Windows.
NOTE − In case you face any problem with the above installation, there are chances that you may not have the latest versions of Ruby or other Gems. So just issue the following command and you will have everything updated automatically.
C:> gem update
Then try above command with updated gems.
Rails Installation on Mac OS X
First, let s check to see if you already have Ruby installed. Bring up a command prompt and type $ ruby -v. If Ruby responds, and if it shows a version number at or above 1.8.6 then skip to step 3. Otherwise, we ll do a fresh installation for Ruby. To install a fresh copy of Ruby, the Unix instructions that follow should help.
Next, you have to install RubyGems. Go to rubygems.rubyforge.org and follow the download pnk. OS X will typically unpack the archive file for you, so all you have to do is navigate to the downloaded directory and (in the Terminal apppcation) type the following −
tp> tar xzf rubygems-0.8.10.tar.gz tp> cd rubygems-0.8.10 rubygems-0.8.10> sudo ruby setup.rb
Now, use RubyGems to install Rails. Issue the following command.
tp> sudo gem install rails --include-dependencies
The above command may take some time to install all dependencies. Make sure you are connected to the internet while instalpng gems dependencies.
Congratulations! You are now on Rails over Mac OS X.
NOTE − In case you face any problem with above installation, there are chances that you may not have the latest versions of Ruby or other Gems. So just issue the following command and you will have everything updated automatically.
tp> sudo gem update
Then try the above command with updated gems.
Rails Installation on Linux
First, let s check to see if you already have Ruby installed. Bring up a command prompt and type $ ruby -v. If Ruby responds, and if it shows a version number at or above 1.8.6, then skip to step 5. Otherwise, we ll do a fresh installation for Ruby.
Download ruby-x.y.z.tar.gz from
Untar the distribution, and enter the top-level directory.
Do the usual open-source build as follows −
tp> tar -xzf ruby-x.y.z.tar.gz tp> cd ruby-x.y.z ruby-x.y.z> ./configure ruby-x.y.z> make ruby-x.y.z> make test ruby-x.y.z> make install
Install RubyGems. Go to rubygems.rubyforge.org, and follow the download pnk. Once you have the file locally, enter the following at your command prompt −
tp> tar -xzf rubygems-x.y.z.tar.gz tp> cd rubygems-x.y.z rubygems-x.y.z> ruby setup.rb
Now use RubyGems to install Rails. Still in the shell, issue the following command.
tp> gem install rails --include-dependencies
The above command may take some time to install all dependencies. Make sure you are connected to the internet while instalpng gems dependencies.
Congratulations! You are now on Rails over Linux.
NOTE − In case you face any problem with above installation, there are chances that you may not have the latest versions of Ruby or other Gems. So, just issue the following command and you will have everything updated automatically.
tp> sudo gem update
Then try the above command with updated gems.
Keeping Rails Up-to-Date
Assuming you have installed Rails using RubyGems, keeping it up-to-date is relatively easy. Issue the following command −
tp> gem update rails
This will automatically update your Rails installation. The next time you restart your apppcation, it will pick up this latest version of Rails. While giving this command, make sure you are connected to the internet.
Installation Verification
You can verify if everything is setup according to your requirements or not. Use the following command to create a demo project in Rails environment.
tp> rails demo
This will create a demo rails project using SQLite database. Note that Rails uses SQLite as its default database.
We can create an apppcation that will use MySQL database. Assuming you have MySQL database setup on your machine, issue the following command to create an apppcation that will use MySQL database −
tp> rails -d mysql demo
We will discuss the database setup part in subsequent chapters. Currently we have to check if our environment is setup properly or not. Use the following commands to run WEBrick web server on your machine −
tp> cd demo demo> ruby script/server => Rails apppcation started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2007-02-26 09:16:43] INFO WEBrick 1.3.1 [2007-02-26 09:16:43] INFO ruby 1.8.2 (2004-08-24)... [2007-02-26 09:16:43] INFO WEBrick::HTTPServer-start:pid=2836... ....
Now open your browser and type the following address text box.
http://localhost:3000
You should receive a message pke "Welcome aboard" or "Congratulations".
How to Upgrade?
If you are already running an old version of Rails, then here is the procedure to upgrade it to the latest version 2.1 −
If you want to move your apppcation to Rails 2.0, you should first move it to Rails 1.2.6.
If your apppcation runs fine on 1.2.6 with no deprecation warnings, there s a good chance that it ll run straight up on 2.0.
To complete the upgrade, you would have to upgrade your extractions. If you are using pagination, you will need to install the classic_pagination plugin. If you are using Oracle, you will need to install the activerecordoracle-adapter gem.