====== Installing Ruby on Rails on Windows ====== ===== Pieces You Need ===== * Ruby * RubyGems * Rails (Gem) * A Database Engine ===== Install Ruby and RubyGems ===== Get the latest [[http://rubyforge.org/frs/?group_id=167|One-Click Ruby Installer]], current version 1.8.6-26. Run this, and select all the defaults. This will install Ruby under C:\ruby, and install RubyGems for you. The README at the end of the installation will show you all the versions of each piece that it installed. You need to update gems after installation: $ gem update --system Before continuing, check to see that c:\ruby\bin is in your PATH by typing "path" at a command prompt. This will ensure that you can run ruby.exe from anywhere (which you'll need to run from your project root). If for some reason it's not there, you'll need to add it (how this is done can vary depending on which Windows Version you are running). ===== 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 [[http://www.sqlite.org/download.html|SQLite download page]]: * the [[http://www.sqlite.org/sqlite-3_6_10.zip|SQLite Command Line Tool]] * the [[http://www.sqlite.org/sqlitedll-3_6_10.zip|SQLite DLL]] Unzip them and put the three extracted files in your ruby\bin directory (usually at C:\ruby\bin). Now install the sqlite3-ruby gem: $ gem install sqlite3-ruby -v 1.2.3 ==== How to Install MySQL ==== Download [[http://dev.mysql.com/downloads/mysql/5.1.html#downloads|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 ===== Setting a Rails project is a one-line affair (from the command prompt): $ rails 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 $ ruby script\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 ==== Other resources ==== * [[http://akitaonrails.com/2009/1/13/the-best-environment-for-rails-on-windows|Akita on Rails suggested environment for Rails on Windows]] * [[::getting-started::RubyStack]]: Free, all-in-one installer that includes Apache and MySQL