Ruby on Rails/Getting Started/Install on Windows

Previous: Introduction Index Next: Getting Started/Install on OS X

Installation on Windows

edit

To start, you will need the following components:

  • Ruby
  • RubyGems
  • Rails
  • a driver for your database

Ruby

edit

Install Ruby as a regular application. You might need administrator privileges to install it successfully. Check the Ruby site for the latest version. The Ruby sites provides packages for all OS. Just follow their steps: ruby website

Gems

edit

RubyGems is a packaged Ruby application. Using the gem command helps you installing and deleting gem-packages. Gems allows you to install additional features for your application and easy management of already installed ones. RubyGems is now part of the standard library from Ruby version 1.9.

To verify availability, check the version of gems:

gem -v

It should display the proper version (2.0.0 as of the writing of this book)

Rails

edit

To install Rails, we can use our freshly installed gems (Rails is a gem). Use the console to type

gem install rails

This downloads and install all the needed components on your system. After the installation is done, verify the installation by checking if you have the latest version:

rails -v

It should display the current Rails version (2.3.2 as of writing this guide)

DB Driver

edit

Rails supports a broad range of databases. The default database is SQLite3. You can specify the database you want to use when you first create your Rails project. But no worries, it can be altered any time. For this Wikibook, we will use SQLite3 as database.

To use SQLite3 on your system together with Ruby on Rails, download the latest dll files from the sqlite website. Choose the files that contains the dlls without TCL binding sqlitedll-3 x x.zip. After downloading, copy all the files inside the zip into your Ruby /bin directory

At last, we need to install a gem for our database. Since we are using SQLite3 in this book, we want to install the proper gem:

gem install sqlite3-ruby --version 1.2.3 

Even though 1.2.3 is not the current version, it will work as intended because newer version won't work in Windows

Database Configuration

edit

If your first application is created, take a look inside the /config folder. We need to tell Rails the name of our database and how to use it. Depending on your chosen database during the creation of the Rails application, the database.yml file always look different. Because we decided to stay with the default SQLite3 database, the file will look something like this:

# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as <tt>test</tt> will be erased and
# re-generated from your development database when you run <tt>rake</tt>.
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000


We may now give our database a proper name. Consider giving different names to your "test"- and to your "production"-database. This is especially important when working in a live-environment and you do not want bad data inside your database.

To create your database in our new project environment, we need to run

rake db:create

Rake is a built-in tool, that allows you to run many pre-made programs to ease up development. There is more functionality inside Rake then just creating a database. But one thing at a time. The db:create commando creates the database with the given name (inside db.yml). If you're using SQLite3, you will find a *.sqlite3 file in the /db folder. This is your database, stored in a single, handy file. For practicing and local development purposes, this is ideal because all your data is in one file that can be quickly read and written.