Wednesday, December 15, 2010

Installing Ruby on Rails on Windows


Installing Ruby on Rails on Windows

Pieces You Need

  • Ruby
  • RubyGems
  • Rails (Gem)
  • A Database Engine

Install Ruby and RubyGems

Refer to RubyInstaller.org for the the latest downloads and information.
If you intend installing gems such as sqlite3-ruby (as below), then you likely need the Development Kit, which provides a complete build environment.
You may need to update gems after installation:
$ gem update --system

Install Rails

Rails is easy to install now, thanks to RubyGems. Simply use gem to install it at a command prompt:
$ gem install rails
This will take awhile, so go get a snack. It may even look like it's not doing anything at first, so don't worry that it's hanging. This will install all the code, test code, ri documentation, and RDoc documentation for Rails.

Install a Database Engine

Rails is completely DB-agnostic, so we'll describe how to install two of the more popular Database Engines: SQLite and MySQL.

How to Install SQLite

SQLite is the default database type that Rails looks for, and it's a great, lightweight DB for Development. We'll install SQLite3 here.
You need two files from the SQLite download page:
Unzip them and put the three extracted files somewhere in your path or in the ruby\bin directory. Now install the sqlite3-ruby gem:
$ gem install sqlite3-ruby

How to Install MySQL

Download MySQL Community Server and install it. If you also do PHP programming, check out WAMP for an easy installation as well.
To use MySQL in Rails versions greater than 2.1, you'll also need the MySQL adapter:
$ gem install mysql
Because MySQL is not the default adapter, we'll have to edit our database.yml file later.

Setup a First Project

Note: Rails 3 is now installed by default; these instructions refer to Rails 3.
Setting a Rails project is a one-line affair (from the command prompt):
$ rails new myprojectname
This will build a directory, in which it will build the entire blank Rails project skeleton. To see your fresh project in action, navigate to your project root and run script\server:
$ cd myprojectname
$ rails server
Then, navigate to http://localhost:3000/ in your browser, and you should see the default Rails “Welcome Aboard” page.
Out of the box, Rails uses the SQLite3 adapter and creates the DB in the db directory. If you look at your database.yml file (in \config), you'll see a database entry for your development, test, and production databases. Each should look something like this:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
This means in development mode Rails is using the sqlite3 adapter to communicate with the database at db\development.sqlite3. This is fine during development, but in production, you'll probably want something beefier. You can change any of the entries to read from a different database type. Here's what an example MySQL entry would look like:
development:
adapter: mysql
database: myprojectname_development
username: devrailsuser
password: devrailspassword
host: localhost
http://wiki.rubyonrails.org/getting-started/installation/windows

No comments:

Post a Comment