Nov 2, 2007

Quick Ruby on Rails on Ubuntu 7.10 (and 8.04 and 9.04)

There are many howto's on this subject out there, but since I ended up blending a few of them to get exactly the environment I wanted setup (and took notes so I could repeat this), I thought I'd blog it for future reference, and hopefully this info is useful to others.

So, what exactly do I want: a development and deployment machine with the following specifications:
  • A recent Ubuntu Linux, in this case 7.10 (Gutsy Gibbon) [update: I also installed on 8.04, hardy heron beta, with good success]
    [update2: I have now installed on 9.04, with a few changes]
  • Web-App server comprised of apache2, mongrel, ruby on rails, mysql5
  • Development environment comprised of Aptana RadRails (based on eclipse), for both Java and Ruby on Rails development (I use Java for other projects, but also plan to do some JRuby work), and since eclipse rocks, I use it for everything I can, even rails. If you don't want java development, you can use the pure Aptana IDE, but then you also loose out on CVS support).
  • Some additional libraries for graphics and charting support in the rails apps.
The quickest setup procedure that worked for me, on four very different computers, a Dell Precision 380 desktop, an Acer Aspire 3100 laptop and most recently a Packard Bell quad core workstation and Acer Aspire 7530G, was:
  1. Install ubuntu. I simply did a standard install from the live cd (downloaded from
  2. Update all packages. I usually just click the update icon on the top right of the screen, but you can use synaptic ('mark all updates' and then 'apply'), or apt-get with the following commands:
    • sudo apt-get update
    • sudo apt-get upgrade
  3. Install packages required for this setup. I used synaptic, but you could just as easily use 'sudo apt-get install ...':
    • sun-java6-jdk / openjdk-6-jdk (includes a number of other required packages)
    • sun-java6-source / openjdk-6-source (optional)
    • joe (just my preferred old text editor, you choose what you like)
    • flashplugin-nonfree (since I will need that for some sites I view/develop)
    • ruby-full (bundles a bunch of ruby packages, including irb, rdoc and ri, but not rake and rubygems, see later for those - do not install them as ubuntu packages now)
    • apache2 (provides version 2.2)
    • mysql-server (provides version 5.0)
    • libsqlite3-dev (required for the gem install of sqlite3-ruby, if you need that)
    • build-essential (provides a c/c++ development environment required by some ruby gems which build on install)
    • libmysqlclient15-dev (required by the mysql ruby library)
    • eclipse (for 3.2 support in ubuntu 7.10 and 8.04) - to get eclipse 3.3 or 3.4 you need to download it from
    • On recent versions of Ubuntu (like 9.04) you also need to install xulrunner as described at this link. This is to get around a library issue between SWT (in eclipse) and Firefox3.0.
  4. Install rubygems from source. This is a contested point, as ubuntu provides rubygems as a package also, but since it is a package management facility itself, it can conflict with the debian package management provided by ubuntu, so it is easiest to keep it completely separate:
    • wget
    • tar xzvf rubygems-1.3.4.tgz
    • cd rubygems-1.3.4
    • sudo ruby setup.rb
    • sudo ln -s /usr/bin/gem1.8 /usr/bin/gem # This was not required for rubygems 0.9.4, but is required now on ubuntu with rubygems 1.0.1 and above
    • sudo gem update --system # With 0.9.4 I needed to repeat this as the first time gave an error, but with 1.0.1 and 1.3.4 it worked first time
  5. Use rubygems to install rails and some other useful gems using the command 'sudo gem install X' where X is any number of the following (I did all):
    • rails # this includes dependencies like rake
    • mongrel # for the deployment server
    • mongrel_cluster # if you want to try out clustering
    • capistrano # if you want to do the easy deployment as described in the 'agile' book
    • mysql # for mysql database access from ruby
    • termios # well, this was mentioned in several blogs and the agile book, so I just did it :-)
    • sqlite3-ruby (sqlite3 is now the default database in rails2, so you might need this)
  6. Add the Aptana Radrails plugins to the eclipse IDE:
    • Start eclipse from the applications menu
    • Go to menu 'Help->Software Updates->Find and Install'
    • Select 'Search for new features to install' and click 'Next'
    • Click 'New Remote Site'
    • Enter name as 'Apatana' and URL '' and click OK
    • Click 'New Remote Site' again
    • Enter name as 'Apatana Radrails' and URL '' and click OK
    • Click 'finish' to start the search for updates
    • Once the search is complete, you should check both 'aptana' and 'aptana radrails' and click 'next' to install
    • Accept the license agreement and click 'next' and then 'finish' to start the actual download
    • When prompted click 'install all' to finish the install
    • Restart eclipse
  7. Modify Eclipse to use Java6 (based on For Ubuntu 8.04 and 9.04, this was not necessary, but I did it for Ubuntu 7.10 and earlier.
    • edit /etc/eclipse/java_home and move java6 up in the list so that eclipse uses java6 for running itself (which is faster)
    • To get projects inside eclipse to use java6, open eclipse and go to the menu 'Window->Preferences->Java->JREs' and select the Java6 JRE.
  8. Add some extra libraries to rails (optional, depends on your apps):
    • I wanted ImageMagick for photo uploads and resizing in my rails apps, so I installed the ubuntu package for ImageMagick using synaptic, and then installed the rubygem 'mini-magick'. I had tried 'RMagick', but the gem did not install, and online help indicates that you need to re-install ImageMagick from source to get RMagick to work, so I opted for the simpler mini-magick.
    • For charting support in my web apps, the popular approach of using 'gruff' wrapping ImageMagick seemed to generate a lot of help requests, so I went for the lighter approach of using client side flash as described in the following blog.
    • For nicer color control, I installed pdf-writer to get the color-tools gem (and in case I needed pdf-writer itself for future development).
  9. Once you have created a rails app, using the usual 'rails myapp', you should consider adding a number of cool rails plugins. There are a huge number out there. Currently I'm using attachment_fu, will_paginate, acts_as_state_machine, restful_authentication and ext_scaffold. See some of my more recent blogs for some more info on these.
  10. Miscellaneous. I also changed my ubuntu font sizes down to 9pt on 'system->preferences->appearance' to get a bit more screen real-estate on the laptop. Windows uses smaller fonts so it looks better (to me), especially when developing in an IDE like eclipse where it is nice to have many panels open together. And for some reason the Ubuntu install had visual effects disabled (Composite extension not available), so I needed to edit /etc/X11/xorg.conf and change the "0" to a "1" on the Composite line near the end of the file. And I changed the theme to 'glossy' but with 'human' icons and darker colors. Looks cool now!
Well, quiet a few steps, but most of the time the computer is downloading packages, updates, plugins and gems from the internet, so you can just lounge around with a good latte :-)

And of course the required screenshot, this one is of the Acer laptop with firefox showing this page and eclipse with a Ruby on Rails application in production (ubuntu 7.10).

Next steps - there are lots of blogs out there on setting up production deployments for rails, and here's one I just read:


Craig Taverner said...

I confirmed that this works fine on Ubuntu 8.04 (Hardy Heron) Beta. I also noticed I forgot to mention the actual installation of eclipse. I did this both through the ubuntu packages (eclipse 3.2) and through manual download for eclipse 3.3. (but only 3.2 provided the aptana updates described).

Craig Taverner said...

Updated instructions for rubygems 1.0.1 (was 0.9.4 in original post). This involved a new wget url, an additional manual soft link and the deprecation of the -y option.

Craig Taverner said...

I also needed the libsql3-dev package to get the sqlite3-ruby gem to install. So use 'sudo apt-get install libsqlite3-dev' before 'sudo gem install sqlite3-ruby', if you plan to use sqlite3 (default in rails2)

Anders said...
This comment has been removed by the author.
Anders said...

Thanks Craig for a wonderful guide.

I've tried a dozen of guides but this is the best. With your guide I succeed to install rails on my laptop but I got an error-message on my desktop. I guess it is because I tried (on my desktop) all variant before yours and haven't successfully removed all files from it.

Anyway here is the message:
anders@anders-desktop:~/Rails/railsapp/work/demo$ ruby script/server
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at
** Starting Rails with development environment...
/usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:159:in `require_frameworks': no such file to load -- openssl (RuntimeError)
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:88:in `process'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:49:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:49:in `run'
from /home/anders/Rails/railsapp/work/demo/config/environment.rb:13
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
... 22 levels...
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from script/server:3

Any suggestions?

Thanks in advance!!

Craig Taverner said...

Thanks Anders, for the positive comments. Concerning you desktop issues, if you have doubts about the integrity of your installation after playing around so much, perhaps a re-install is wise. Having said that, I think the error message you got gives a good hint as to the problem. It said 'no such file to load -- openssl'. If you look at the dependencies of the 'ruby-full' package, you will see 'libopenssl-ruby', and I would guess there is a good chance that that package is missing or corrupt (or rather libopenssl-ruby1.8, which is the real package that libopenssl-ruby represents). Try 'dpkg -l | grep openssl' to list what you have (I have libopenssl-ruby, libopenssl-ruby1.8, openssl and ssl-cert). Do this on both the latop (working) and the desktop (broken) and compare the results. Try re-install the packages. You could even trying removing openssl, and ruby and re-install them both again. Good luck.

Anders said...

Thanks Craig for your advice!

I guess I have no luck....with this.

There were no difference between the lists.

I re-installed the packages but unfortunately I still got the same error on my desktop AND I got another error message on my laptop when do the ruby script/server: "undefined method 'time_zone=' for #Rails::Configuration:0xb78a7228 (NoMethodError)". I don't what I have done...

Best regards,

Craig Taverner said...

I've never seen that before, but a quick google search on your error message lead me to here.

This seems to indicates that you might have a gem source for development gems, and you should remove it. The command 'gem sources -l' should only list the rubyforge source, and you can remove the rails source with 'sudo gem sources -r'.

Since I do not have this problem, I'm not sure this really is the solution. Give it a try and otherwise search further with google.

Anders said...

Hi Craig!

It is solved now. As you recommended I did a lot of google search and in the end I got it right. I reinstalled ubuntu and installed as the following:

RUBY="ruby-1.8.6-p111" (aktuell version)
tar xzvf $RUBY.tar.gz
cd $RUBY
./configure --prefix=/usr/local --with-openssl-dir=/usr --with-readline-dir=/usr --with-zlib-dir=/usr
make && make install

By default, Ruby will be installed under /usr/local. A simple which ruby should now point you to /usr/local/bin/ruby. A quick ruby -v should report the version and patchlevel from the downloaded Ruby source package. In our case it is ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux].
By default, the bash configuration in Ubuntu includes a path to /usr/local/bin. That’s why the above statements work out of the box without changes to your shell configuration.
To make sure that all the necessary libraries are accessible from within Ruby use the following command line:

ruby -ropenssl -rzlib -rreadline -e "puts :success"

If this command only returns the string success the installation is working as intended.
To speed up the compilation process you can skip the documentation generation step make install-doc by removing it from the above make line.
Installing RubyGems
Once your custom Ruby environment is available you can proceed to install RubyGems. The latest version as of this writing is 1.1.1:

RUBYGEMS="rubygems-1.1.1" (or current version)
tar xzvf $RUBYGEMS.tgz
/usr/local/bin/ruby setup.rb

Again you can test the installation with which gem and gem -v. It should be located in /usr/local/bin.

And then I installed rails, mongrel and the other stuff according to your instructions. It was perfect.

Thanks again for your help!

Craig Taverner said...

Anders, while your approach works, it is not really necessary to do a complete manual re-install. You just need to remove the 'development gems' that have infected your system (rails To my surprise, I just got the same error today on my mail rails development machine, after creating a new rails project. And then when I did a 'gem sources list', I found the offending listed. I am embarrassed to say I don't know how it got there, but there it was, and 'gem list' also showed all the rails gems has being installed with both version 2.0.2 and

So, fixing it was easy. I removed the source with 'sudo gem sources -r' and then removed all the development gems with commands like 'sudo gem uninstall rails -v' (repeated for all rails gems). Then I created a new project and everything worked fine.

So it is possible to fix this problem without a heavy duty manual reinstall of rails.

Craig Taverner said...

I think I've found out where the development gems source is coming from. I just did a 'sudo gem update' command, and to my amazement, it re-included the source and re-installed the development version of rails ( So it seems the upgrade to rubygems 1.1.1 has decided to automatically include that source.

I then repeated the un-installation of the source and the development gems, using the commands:
sudo gem sources -r
sudo gem uninstall rails actionmailer actionpack activeresource activesupport -v
And everything was fine again, and even the command 'sudo gem update' did not bring back the bad gems. It seems it only caused a problem when it was upgrading rubygems itself. So the fix has now stuck. Let's hope that the next time they upgrade rubygems they don't do this again :-)

SecularAugust said...

On Ubuntu 8.04 (Hardy) I already had an old copy of Gems around. It caused sudo ln -s /usr/bin/gem1.8 /usr/bin/gem to fail to create a new link... and all the subsequent commands involving gem to kick back the error:

"/usr/bin/gem:23: uninitialized constant Gem::GemRunner (NameError)"

I removed the old gem by hand (sudo mv gem gem_old), created the link, and then all the gem commands worked.

Craig Taverner said...

I've tested this now on Ubuntu 9.04, and it worked in most cases. I was unable to get eclipse 3.4.2 to work, but everything was fine with 3.3.2. One possible change was the aptana download location, but just check at for the latest information.

Craig Taverner said...

After installing Aptana in eclipse 3.3 on Ubuntu 9.04, I had problems with the swt-mozilla-gtk library:

No more handles (java.lang.UnsatisfiedLinkError: no swt-mozilla-gtk-3349 or swt-mozilla-gtk in swt.library.path, java.library.path or the jar file)

This was fixed by the command sudo apt-get install xulrunner as discussed on the blog 'Fixing Eclipse after the Firefox 3 rc1 update in Ubuntu 8.04'.

I have updated the instructions above to include this information.

Unknown said...

It is great stuff about ruby on rails development services and a must read for ruby on rails consultants .