Solr gem and xml ruby gem How it matters

If you use solr-ruby gem, you should be well aware that Solr attempts to create an XML doc from the provided doc-hash. It first attempts to use ‘xml/libxml’, which if not available, falls back to REXML. It is recommended to use libxml.

All you need to do is


gem install libxml-ruby

If you are lucky enough, that’s all for you. However, many a times we face issues like


Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for socket() in -lsocket... no
checking for gethostbyname() in -lnsl... yes
checking for atan() in -lm... no
checking for atan() in -lm... yes
checking for inflate() in -lz... no
checking for inflate() in -lzlib... no
checking for inflate() in -lzlib1... no
checking for inflate() in -llibz... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

If this is the case, you should install zlib-devel and libxml2-devel packages.


yum -y install zlib-devel
yum -y install libxml2-devel
gem install libxml-ruby

That sorts it all. You are good to go

ruby fetch_hash ArgumentError: NULL pointer given

Recently, One of our servers started to have the following error

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mysql'
=> true
irb(main):003:0> conn = Mysql.connect('db01', 'xxxxxx', 'xxxxxx', 'employee')
=> #
irb(main):004:0> a = conn.query("SELECT * FROM employees WHERE id >= 8500 AND id < 9000")
=> #
irb(main):005:0> a.fetch_hash
ArgumentError: NULL pointer given
    from (irb):5:in `fetch_hash'
	from (irb):5
irb(main):006:0> exit

The method fetch_hash is a standard method and works. Here is the versions of MySQL and ruby that I used

-bash-3.2$ mysql --version
mysql  Ver 14.12 Distrib 5.0.89, for unknown-linux-gnu (x86_64) using readline 5.1

-bash-3.2$ ruby --version
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]

If you face this issue in your servers or anywhere try the following workaround. They have worked for me, and they should work for you as well.

  1. uninstall the MySQL-shared-compat package
  2. Re Install mysql gem