Imaginemos un mundo libre

La paz interior comienza en el momento en el que decides no permitir, que ninguna persona o evento, tome el control de tus emociones.

Hpricot installation problem

with 4 comments

Hpricot is a fast,  flexible HTML parser written in C. Hpricot can be handy for reading broken XML files,  since many of the same techniques can be used. If a quote is missing Hpricot will try to figure it out.

I was really having problems to install hpricot,  the newest version is 0.6.  Whenever I executed:

$ sudo gem install hpricot
Select which gem to install for your platform (arm-linux)
1. hpricot 0.6 (mswin32)
2. hpricot 0.6 (jruby)
3. hpricot 0.6 (ruby)
4. hpricot 0.5 (ruby)
5. hpricot 0.5 (mswin32)
6. Skip this gem
7. Cancel installation
> 3

I received the following message:

Building native extensions.  This could take a while...
ERROR:  While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

I Typed this to see what is going on:

ruby extconf.rb install hpricot

and the error continue

extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1

Gem files will remain installed in /var/lib/gems/1.8/gems/hpricot-0.6 for inspection. Results logged to /var/lib/gems/1.8/gems/hpricot-0.6/ext/hpricot_scan/gem_make.out
$

Googling for a while,  I found a good solution in the hpricot project wiki.  The main problem is that I had ruby 1.8 and 1.9 installed. Ruby 1.8.5 was the version I was using, but I didn’t have development libraries installed.  So, gem couldn’t install correctly hpricot.

You can check your version for ruby, rails, gem and everything else by typing -m after the program name.

$ ruby -v
ruby 1.8.5 (2006-08-25) [i486-linux]
$ gem -v
1.1.1

The solution: There is a file we need,  called mkmf.rb. It has connection with ruby libraries,  so let’s search it.

$ auto-apt search mkmf.rb
usr/lib/ruby/1.9/mkmf.rb        devel/ruby1.9-dev

As you can see, we don't have it in ruby1.8 directory, so let us install ruby1.8 development libraries.

$ sudo apt-get install ruby1.8-dev

and now, we have the mkmf.rb in ruby1.8

$ auto-apt search mkmf.rb
usr/lib/ruby/1.9/mkmf.rb        devel/ruby1.9-dev
usr/lib/ruby/1.8/mkmf.rb        devel/ruby1.8-dev

There is no documentation in the wiki,  but I assume that you have to install another gem called mechanize which is  an hpricot  dependency.

$ sudo gem install mechanize
Install required dependency hpricot? [Yn]
Select which gem to install for your platform (arm-linux)
1. hpricot 0.6 (mswin32)
2. hpricot 0.6 (jruby)
3. hpricot 0.6 (ruby)
4. hpricot 0.6 (jruby)
5. hpricot 0.6 (ruby)
6. hpricot 0.6 (mswin32)
7. Skip this gem
8. Cancel installation
> 3
Building native extensions.  This could take a while...
Successfully installed mechanize-0.6.9
Successfully installed hpricot-0.6
Installing ri documentation for mechanize-0.6.9...
Installing ri documentation for hpricot-0.6...
Installing RDoc documentation for mechanize-0.6.9...
Installing RDoc documentation for hpricot-0.6...

Finally, you will get hpricot successfully installed and now you can use this great gem.

Thanks for your visit to the blog. You can follow me on Twitter:

Written by Ronny Yabar

May 5, 2008 at 9:36 pm

Posted in Ruby on Rails

Tagged with ,

4 Responses

Subscribe to comments with RSS.

  1. Hi!

    In Fedora, it must be installed like that:


    su
    "password root"
    yum install ruby-devel
    gem install hpricot

    bye!! ;)

    albertito

    August 1, 2008 at 8:48 am

  2. I believe if you install ruby from scratch you don’t have this problem.

    roger

    August 26, 2008 at 4:45 pm

  3. I’m having a similar problem in WinXP. How do I fix it?

    LG

    October 22, 2008 at 11:30 am

  4. LG , Sorry, but actually I don’t use windows and I can not give you a helping hand.

    ronnyml

    October 29, 2008 at 2:54 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: