Installing libxml-ruby for libxml2 with Ruby, on OS X

Update 2012: This material was written in 2006. Now, many years later, it still poisons the search engines with its presence. If you want to use Ruby and a package manager on OS X, you should use RVM and Homebrew. I will leave this page here as a warning to you, dear reader. Do not take detailed old technical Ruby recipes as advice.

Just had an exciting package management adventure with Ruby and XML on OS X. I wanted Libxml2 wrapped in a Ruby gem. So, I ran

sudo gem install libxml-ruby

…and watched the software fail to build. Darn OS X not “just being Linux”. After complaining to Christoffer, I was kindly pointed to a MacPort:

sudo port install rb-libxml2

OK, that worked. But I don’t want to use DarwinPorts/MacPorts for my Rubygems, the gems change far too often for that. What I wound up doing was reinstall my gem (sudo gem install libxml-ruby), and then copy the libxml.bundle to its folder:


# cp /usr/local/lib/ruby/gems/1.8/gems/xml/libxml.bundle \
/usr/local/lib/ruby/gems/1.8/gems/libxml-ruby-0.3.8/ext/xml/

Also, go into the file

/usr/local/lib/ruby/gems/1.8/gems/libxml-ruby-0.3.8/ext/xml/libxml.rb

and change the required file’s name from xml/libxml_so to xml/libxml.bundle.

This was enough to make the thing work!

Moral: The right way to fix this would be to enhance the Makefile of the libxml-ruby gem to teach it about the OS X environment, but: not me, not today. This little tip is what I can do today. Ciao.

Published by Olle Jonsson

Human. Wears glasses and often a smile.

Join the Conversation

2 Comments

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.