Installing Ruby on Ubuntu Server with Mechanize gem
I wanted to use Ruby on my server for several scripts (one of these uses the Mechanize gem). It turned out it was quite some mission to get this done. Therefore I wrote a small tutorial so you don’t have to spend so much time in finding solutions.
FYI, Mechanize is a library which simulates a browser, including history, forms etc. Quite useful for coding crawlers, but as well for automated form submitting.
In order to install Ruby do:
The ruby package contains ruby itself, rubygems is needed in order to use gems (i.e. Ruby extentions) and ruby1.8-dev is needed in order to compile some gems correctly.
We want to use the Mechanize gem as well. When I wanted to install this gem it turned out I missed some libraries. So we first install these:
Now it is time to install Mechanize itself:
During the install you should have console output like:
Successfully installed nokogiri-1.4.1
Successfully installed mechanize-1.0.0
2 gems installed
Installing ri documentation for nokogiri-1.4.1…
No definition for get_options
No definition for set_options
No definition for parse_memory
No definition for parse_file
No definition for parse_with
Installing ri documentation for mechanize-1.0.0…
Installing RDoc documentation for nokogiri-1.4.1…
No definition for get_options
No definition for set_options
No definition for parse_memory
No definition for parse_file
No definition for parse_with
Installing RDoc documentation for mechanize-1.0.0…
You are finished now with installing Ruby and the Mechanize gem it might be that you get errors like the one shown below when you execute your script:
/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’: no such file to load — net/https (LoadError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require’
from /var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:2
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require’
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:36:in `require’
from isup.rb:2
Thanks to this website, I could solve this problem by doing:
Happy Ruby coding!

Small typo in your last command:
sudo apt-get install ibopenssl-ruby
should be:
sudo apt-get install libopenssl-ruby
@Tim thanks! Changed it