Setup Ruby on Rails On Windows Vista
by Saurabh Bhatia
October 20, 2009
|
Having trouble getting Ruby on Rails running on Windows
Vista or just want to know how? Suarabh Bhatia details the
basics to get the RoR framework up and running.
|
Introduction
Ruby Programming Language has been around since 1995.
Created by Yukihiro
"matz" Matsumoto in Japan, Ruby started gaining
popularity around the world after its first English
documentation, Programming Ruby, came into being. Rails was
developed as a Web development framework for projects at
37signals and was released to the Public in 2004 and became
an instant revolution. The subsequent years saw a huge
explosion in terms of community growth, which led to a quick
maturity of the Ruby Language and the Rails framework.
The task on hand today is to get a basic Ruby on Rails
Development environment running on our Windows Vista
machine. Once we are through with this article you will have
the Ruby Language, the Rails Framework, the Application
Server, a source control system to manage versioning of the
code you write, Rubygems to manage Ruby based packages,
MySQL Server and the client for the database.
System Requirements:
The Minimal hardware configuration required for the
Development environment is 256 MB RAM, a CPU speed of
minimum 1 GHz and a disk space of 50 MB.
On the Software side, make sure your Vista is up to date
with the latest patches and security updates and that you
are logged in as an administrator to avoid permission
problems with installation of the software.
The Ruby Primer
The Ruby package for Windows is called One Click Ruby Installer and can be downloaded
from Rubyforge.org, the
primary source for most of the software available for Ruby.
Now a days, a lot of Ruby related software can also be found
out at Github. Figure 1 shows the downloaded One Click Ruby
Installer. The current running version of Ruby for Windows
is ruby1.8.6-27_rc2.

Figure 1
Once downloaded, run the installer. Select all the
default options, as shown in figure 2 and wait for the
installer to finish the work.

Figure 2
At the end of this, a folder named Ruby will be created
inside your C: drive, or whichever drive you have selected
during the time of installation. To make sure Ruby is
installed properly on your system, open up the command
prompt by typing cmd in your run box, from the start menu.
Type the command:
C:\> ruby -v
Ruby -v 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
If you get this output as shown on your command line, you
have installed Ruby correctly. If not, you should uninstall
all the components of Ruby and try running the installer
again. Ruby comes with a bunch of goodies with it's basic
installation. Apart from the Ruby language interpreter it
installs irb, an interactive interpreter for Ruby, Scite a
text editor with coloration support for a lot of languages,
a web server named Webrick , support for Rubygems, a
packaging mechanism native to Ruby and a book in the form of
chm, named, Programming Ruby. What more can you ask from a
basic installation of a Language?
Irb can be accessed anytime by opening the command prompt
and simply typing irb. Check figure 3 to see how to access
irb.

Figure 3
Coming back to our subject of installing the Rails
development stack, we will proceed with the installation of
Rubygems. Most of the software written in Ruby is packed and
distributed as .gems. Gems once installed are available
system wide for use. Rubygems is a program for the system to
recognize gem packages and creates gem bindings with the
Ruby Interpreter.
Go to Rubygems download page on Rubyforge and
download the latest zip package of Rubygems. We have used
version 1.3.5 for this tutorial. After the download is over,
navigate to the Download path and unzip the package with a
suitable utility( WinRar or WinZip). Open the command prompt
and change the directory to the path of Rubygems unzipped
folder. Once inside, type the command:
C:\> ruby setup.rb
Rubygems will go through the installation and return the
cursor to the command prompt. To verify our Rubygems
configuration, we need to simply type:
C:\> gem -v
1.3.5
The display of the correct version of Rubygems is
indicative of the correct configuration.
The Database
MySQL is the most popular open source database in the
market these days and is quite a popular choice around the
globe. In fact it was the default database for Rails until
Rails 2.0.2 when SQLite became the default database.
To Install MySQL, Download the MySQL 5.4 Windows MSI
package and run it.

Figure 4
Select the setup type as typical, set the port number as
3306 in the next screen and just press next for the screens
to follow. The package will install and will reach a finish
screen. "MySQL server configuration wizard" will start.
Select detailed configuration, install as Windows service
and proceed to the further screens by simply selecting next
option in the installation dialog box. Setup the password
for MySQL in one of the screens. This will be the root
password for MySQL. Check Figure 5 to see how to set the
root password.

Figure 5
Setting this would finish your MySQL setup. Lets verify
the MySQL settings and check to see if it is working
properly or not. You would see a MySQL command line in the
menu. Clicking on that would open the command prompt and
will ask you for the root password. Type in the root
password and if it logs in with your credentials, your MySQL
is setup.

Figure 6
In order to manage MySQL databases more efficiently we
will also install GUI tools, like MySQL Administrator and
MySQL Query browser. These tools are bundled up as a single
.exe package and is freely downloadable from MySQL mirrors
site.
Through with our database and Ruby setup, lets move on to
setting up Rails and other components.
Rails and Friends:
Once the above setup is done, installing Rails is a
fairly straightforward task. Simply type the command:
C:\> gem install rails
This command will install the latest stable release of
Rails. However, if you want to install a specific version of
Rails, you need to do:
C:\> gem install rails -V="1.2.5"
When a gem package is installed, there are 3 kinds of
packages installed on the system, the gem package and it's
dependencies, the ri documentation and the rdoc
documentation.
Now that we have the Rails framework installed on our
system, we need a database connector, in order to connect
our Rails framework to the MySQL database installed.
C:\> gem install mysql
Running the above command does the trick most of the
time. However we need to take care that MySQL gem gives
various problems related to the installation path. In order
to resolve that, we can compile it with various options
manually defined.
Mongrel is a Rails application server which uses webrick
as the base and is a pure Ruby implementation of an
application server. We would prefer to run our Rails
applications inside Mongrel. So let's install Mongrel and
the mongrel_cluster.
C:\> gem install mongrel mongrel_cluster

Figure 7
Source Control
As Rails is a highly productive framework, all the teams
using Rails are bound to use Agile and Xtreme programming as
a de facto standard. Keeping this in mind, a version control
system is a must for all the development environments.
Subversion used to be a standard choice, till 2007 but in
previous years, Git has taken over Subversion in popularity,
at least in the Rails world, because it supports distributed
teams and distributed development. We will go through steps
to setup Git locally in our systems.
Git is a Linux program natively because of its roots and
is ported on Windows as an open source project hosted on
Google Code called Msysgit. Download the Git-1.6.4-
preview20090730, the .exe file and run the installer. As
shown in figure 8, Git Bash and Git GUI, should be selected
during the installation. This installs the Git commands on
the system.

Figure 8
Being a Windows use, we want a gui to manage our Git
repositories, we can install a front end for
Git. Subversion users should find it easy to migrate to
Git.
We are through with the installation, lets run a few
commands on Rails to test how things are.
C:\> rails testapp

Figure 9
We will fire up the server and check to see if it's
running fine or not. To do so, we change the directory to
our application directory and run the command:
C:\testapp> mongrel_rails start

Figure 10
If your Windows firewall is on, it will ask for 'blocking
or unblocking" the Ruby interpreter. Select Unblock and we
have our server up and Running.
Rails server, mongrel or webrick, runs at Port Number
3000, so open up the browser and type: Localhost:3000 in
your address bar. You will be presented with a Rails default
index page.

Figure 11
Congratulations! We have successfully installed Ruby on
Rails on our system. Now we are ready to develop super cool Web
applications in Ruby on Rails.
|