====== Installing Ruby on Rails on Windows ====== ===== Pieces You Need ===== * Ruby * RubyGems * Rails (Gem) * A Database Engine ===== Install Ruby and RubyGems ===== Refer to [[http://rubyinstaller.org|RubyInstaller.org]] for the the latest downloads and information. RubyInstaller package already bundle latest version of RubyGems. Some gems might require a compiler (like RedCloth) and under some cases libraries and headers specific to them. Refer to the gem documentation for special instructions. As for Ruby on Windows, you will need to download and install [[http://rubyinstaller.org/downloads/|Development Kit]], which provides a complete build environment. ===== 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. We will install the gem first: $ gem install sqlite3-ruby After installation, it will display a notice indicating some manual actions required to complete installation. To summarize them: You need two files from the [[http://www.sqlite.org/download.html|SQLite download page]]: * the [[http://www.sqlite.org/sqlite-3_7_2.zip|SQLite Command Line Tool]] * the [[http://www.sqlite.org/sqlitedll-3_7_2.zip|SQLite DLL]] Unzip them and put the three extracted files somewhere in your path or in the ruby\bin directory. ==== 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 [[http://www.wampserver.com/en/|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, and the GEM list. For more information on [[database-support:mysql|MySQL]]. ===== 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 ==== 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 * [[http://jruby.org/|JRuby]]: Ruby running on the JVM (Java Virtual Machine)