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: Follow @ronnyml