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.
sailesh says
Good to see you progressing & knowing more :)
Ethan says
That’s awesome, man. Congrats on getting your VPS going. Are you going to get into running a cluster of Mongrels using Apache or Nginx?
avinash says
Hi Ethan,
I am going to use a small cluster of two or three mongrels through the load balancer of Apache. I don’t know anything about Nginx but I’ll have a look.
Thanks for the input.
ames says
Time for an update: http://weblog.rubyonrails.org/2007/12/7/rails-2-0-it-s-done
This site runs on 2.0 btw: http://www.omninerd.com/
Sir, have fun :)
Christopher Williams says
I know this is an old column, but just to correct something here: the -B bulk threshold is the number at which rubygems switches from incremental updates of gems to updating the entire index. In practice this means that if there are less than 1000 gems it’ll update them individually, if more it’ll grab the full index and rebuild from scratch. The rebuild is much faster, but eats up tons of memory, while the incremental will work on low RAM boxes but will be much slower when there’s a lot of gems.
avinash says
Thanks a lot for this clarification Christopher :-)