Installing Ruby on Ubuntu Server with Mechanize gem

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:

# apt-get install ruby rubygems ruby1.8-dev

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:

# apt-get install libxml2-dev libxslt-dev

Now it is time to install Mechanize itself:

# gem install mechanize

During the install you should have console output like:

Building native extensions. This could take a while…
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:

[email protected]:/home/bas/ruby# ruby isup.rb
/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:

# apt-get install libopenssl-ruby

Happy Ruby coding!

3 thoughts on “Installing Ruby on Ubuntu Server with Mechanize gem

  1. Small typo in your last command:

    sudo apt-get install ibopenssl-ruby

    should be:

    sudo apt-get install libopenssl-ruby

    😀

Leave a Reply

Your email address will not be published. Required fields are marked *