“if you were independently wealthy and didn’t need a job at all, would you still be writing software for fun?â€
If the answer to this deep philosophical question is yes then you are a geek. Congratulations!
“if you were independently wealthy and didn’t need a job at all, would you still be writing software for fun?â€
If the answer to this deep philosophical question is yes then you are a geek. Congratulations!
As you know, I now have my own virtual private server hosted at Slicehost and on which I’ve installed the latest Ubuntu 7.10 Gutsy Gibbon.
The main reason why I’ve changed my hosting company is that I want to have fun with Ruby on Rails and Ruby technologies in general.
Installing the infrastructure to run Ruby on Rails applications is not difficult but there are some steps which are not trivial. Here is a rundown of what I did to get my first Ruby on Rails application working online.
1 – Ruby and Rubygems
The server edition of Ubuntu does not install Ruby and the Ruby package manager (called Rubygems) out of the box. I did:
$ aptitude install ruby
$ aptitude install rubygems
This installs Ruby 1.8.6 and a relatively troublesome version 0.9.4 of Rubygems that needs to be updated as quickly as possible to a newer version. The reason is that this old version of Rubygems uses too much memory and will fail on my 256Mb slice! To install the new version (0.9.5), I did:
$ gem update --system --source http://segment7.net/
$ gem update --system --source http://segment7.net/
This installs a beta version (0.9.4.7) of Rubygems which works well when memory is limited. Notice that I typed that line twice. It failed the first time but succeeded the second time. Your mileage will, of course, vary. I then did:
gem update --system
and, voilà , the latest Rubygems (0.9.5) is installed. As a confirmation, here is what I now have:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 0.9.5 (0.9.5)
- RUBY VERSION: 1.8.6 (2007-06-07 patchlevel 36) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org
The most important information is the :bulk_threshold => 1000 which indicates that Rubygems will limit its memory consumption to 1000 units (kb?) which rocks! Now, everything can be installed without exceeding the memory of the server.
2 – Ruby on Rails and Mongrel
Now that Ruby and Rubygems work well, it’s high time to install Ruby on Rails and its friend, Mongrel.
Mongrel is (I quote once more) “a fast HTTP library and server for Ruby that is intended for hosting Ruby web applications”.
Before installing those two Ruby gems (which is what Rubygems call an add-on package), I did:
$ aptitude install build-essential
$ aptitude install ruby1.8-dev
build-essential contains a C/C++ compiler which is crucial when installing some gems because, well, some of them are written in C/C++… Furthermore, ruby1.8-dev contains some essential tools when are required for installing gems. Both are important because gems are downloaded in source format (in either C/C++ or Ruby) and need to go through a number of steps before actually being installed.
I installed Ruby on Rails and friends with:
$ gem install rails
$ gem install mongrel
$ gem install mongrel_cluster
3 – Testing Ruby on Rails and Mongrel
I then created a skeleton Ruby on Rails application:
$ cd
$ rails test
$ cd test
and I launched a Mongrel instance on port 81 (because I can’t access my server from my client if the default port of 3000 is used…) with:
$ ruby script/server -p 81
and the result I got was:
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:81
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:81
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel 1.1.1 available at 0.0.0.0:81
** Use CTRL-C to stop.
which felt like music to my ears.
I’ve stopped the server since. So you won’t be able to connect to it. But for your own enjoyment, feel free to stare on the above screenshot :-)
Conclusion
The process is easy and well documented elsewhere. Except for the bloody Rubygems issue which forced me to hard_reboot my VPS for the first time in its (short) life.
Next time, I’ll write something on using Capistrano to deploy a Ruby on Rails application automatically.
Did you notice that my weblog is not hosted at Icdsoft anymore? I have moved to a shiny virtual private server courtesy of Slicehost which uses virtualization to run multiple operating systems (hence multiple VPS) on the same server.
I first heard of Slicehost about two months ago when looking for a hosting company supporting Ruby on Rails (which unfortunately Icdsoft isn’t). Their VPS plan includes (I quote):
Two (small) glitches
First of all, they don’t accept customers if they feel they don’t have the hardware resources. In that case, you are put on a waiting list and they order new hardware. That why I had to wait two months to move to Slicehost. Now, this “glitch” is also a benefit in the sense that you know that everything will be great once you are accepted.
The second glitch is the price. The smallest hosting plan called 256slice (with 256MB of RAM, 10GB of HD space and 100GB of monthly transfer) is $20 per month. Now, this is mostly negligible for an American or a company but not for me.
I’ve managed to convince Christina that this is worthwhile for two reasons: