source code bean

08 Jan, 2011

Setup Ruby on Rails development environment

Posted by: Peter In: Ruby on Rails

When Rails 3 was released a coworker was very excited about it and he convinced me to give it a try. I have tried different version of Rails 1 and version 2, but at the time something about it didn’t really feel right to me, so I decided to stick to PHP for my own web projects and .NET for my professional work.

My coworker recommended to read the tutorial on http://railstutorial.org. After giving it a try and playing around with some applications for about 2 months now, I must say that I am really impressed. Everything in Rails is super streamlined for developing web applications.

Setting up your development environment is actually quite easy, no matter what OS you are on. I have tried both on my Mac and on my Windows 7 machine. Let me show you how to set it up on Windows:

Step 1 – Install Ruby
The first step is to download and install Ruby from http://rubyinstaller.org. Make sure you install it to a path that does not include any spaces, like “C:\Program Files”, this is known to cause a lot of issues. Best is to stick with the default, for version 1.9.2x it is “C:\Ruby192″.

Step 2 – Install Rails
Open up a Powershell terminal and execute:
gem install rails

This will install the latest version of Rails on your system.

Step 3 – Install SQLite binaries
We need a database, for development it is recommended to use SQLite since it needs almost no setup or configuration. Grap the latest binary for windows on http://www.sqlite.org/download.html. The zip should contain two files, sqlite3.def and sqlite3.dll. Extract the zip to the bin directory of your ruby installation, in my case “C:\Ruby192\bin”.

Now you need to install the sqlite-ruby gem (the database adaptor for rails).
gem install sqlite3-ruby

Step 4 – Create an application and try it out
Now you can create a new Rails application by typing:
rails new testapplication

This will create a new rails application in a folder named testapplication. Go into the folder and execute:
bundle install

This installs the Gems required to run the application. Start the application by typing
rails server

PS C:\dev\testapplication> rails server
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-01-08 13:09:36] INFO WEBrick 1.3.1
[2011-01-08 13:09:36] INFO ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0]
[2011-01-08 13:09:36] INFO WEBrick::HTTPServer#start: pid=37700 port=3000

Your application is up running! Browse to http://localhost:3000 and you should find the default “Welcome aboard” page. Now go read the great tutorial at railstutorial.org and build something fun :)



No Responses to "Setup Ruby on Rails development environment"

Comment Form

Adwords

About

Welcome to source code bean! On this site I post stuff that I encounter in my job and spare time. The content is mostly related to .NET development, but my interest in techonology is very broad, so often you will find posts on totally different subjects!