Tuesday, July 11, 2006

Installing Ruby and Rails Framework from behind a firewall

I think it is the frustration of not being able to do something very simple that often leads programmers to feel elated to see something as simple as the Hello World printed on the screen.

I mean, if you can do it with a simple "echo Hello World", why do you need all these fancy languages?

Anyway, I have been trying to go where probably a lot of men have gone before. But I am going to leave a map for those that follow.

Task: Install Ruby and ROR framework from behind a firewall.

Part 1. Installing Ruby.

This is faily straightforward.

Just click on the following link and that should give you the executable to install Ruby:

ruby182-15.exe

Note: Make sure C:\ruby\bin is in the path.

Part 2. Installing RubyGems.

Again, click on the link below to get RubyGems zip file:

rubygems-0.9.0.zip

Unzip file file. This will create a directory like C:\rubygems-0.9.0.

CD C:\rubygems-0.9.0
ruby setup.rb

Part 3. Installing Rails.

The documentation asks you to type "gem install rails --include-dependencies". But what if you are behind a firewall? Or even worse, don't have internet connection? It might seem impossible in this day and age, but there are people who don't have internet connection.

You will get a smug little error like:

ERROR: While executing gem ... (SocketError)
getaddrinfo: no address associated with hostname.

Not much descriptive is it? You won't find much help anywhere else either. But here is all the help you will need. This is what you do:

1. Open Internet Explorer and go to rubyforge gems subdirectory. Here, if you say that you don't have internet, well, you will need to go to a Net Cafe and download some files then....and copy these to a floppy.

2. Here, find the following files and save them to your local drive (I am assuming you are saving these to C:\).

a. actionmailer-1.2.3.gem
b. actionpack-1.12.3.gem
c. actionwebservice-1.1.4.gem
d. activerecord-1.14.3.gem
e. activesupport-1.3.1.gem
f. rails-1.1.4.gem

3. Next, go to command prompt and change directory to where you saved the gem files (C:\ in my case) and run the following commands one by one.

gem install activesupport
gem install activerecord
gem install actionwebservice
gem install actionpack
gem install actionmailer
gem install rails

Part 4. Running rails for the first time.

Run the following commands to create a skeleton rails application:

C:
CD rails rails
(This will create a sample application under C:\rails)
CD rails
ruby script/server
(This should kick off WEBrick)
Open a browser and visit http://localhost:3000

Initial WEBrick console should look like:

C:\rails>ruby script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-07-11 13:10:27] INFO WEBrick 1.3.1
[2006-07-11 13:10:27] INFO ruby 1.8.4 (2006-04-14) [i386-mswin32]
[2006-07-11 13:10:27] INFO WEBrick::HTTPServer#start: pid=57 port=3000

After you visit http://localhost:3000, it should look like:

C:\rails>ruby script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-07-11 13:10:27] INFO WEBrick 1.3.1
[2006-07-11 13:10:27] INFO ruby 1.8.4 (2006-04-14) [i386-mswin32]
[2006-07-11 13:10:27] INFO WEBrick::HTTPServer#start: pid=57 port=3000
127.0.0.1 - - [11/Jul/2006:13:13:25 GMT Daylight Time] "GET / HTTP/1.1" 304 0 - -> /
127.0.0.1 - - [11/Jul/2006:13:13:25 GMT Daylight Time] "GET /javascripts/prototype.js HTTP/1.1" 304 0 http://localhost:3000/ -> /javascripts/prototype.js
127.0.0.1 - - [11/Jul/2006:13:13:25 GMT Daylight Time] "GET /javascripts/effects.js HTTP/1.1" 304 0 http://localhost:3000/ -> /javascripts/effects.js
127.0.0.1 - - [11/Jul/2006:13:13:25 GMT Daylight Time] "GET /images/rails.png HTTP/1.1" 304 0 http://localhost:3000/ -> /images/rails.png

Press Ctrl-C here and that should shut WEBrick down.

So now you really don't have any excuse not to get onto Rails.