You can't assume that the version of ruby built-into OS X is compatible with any gems you want to use. Do not try to remove the version of ruby that ships with OS X or update or upgrade it unless with App Store/Software Update/softwareupdate. Most rubiers will tell you don't even bother useing the ruby that ships with OS X. But you can install multiple versions of ruby, and you'll definately need a ruby version manager if you intend to use lots of gems.
ruby was once quite easy to use, but now, the number of versions that necessarily need to be supported are legion, and gem developers sometimes force you to install a new version of ruby at some other version when you already have a perfectly good ruby installation! Grr. ruby is really starting to chafe, because while the support information might be out there, it is looking more and more like a fishing reel that has birdnested. IMO, ruby is broken, someone's going to have to pull it out and get it neatly reeled in for it to be fixed, and I'm just not up to it. I'm not the guy. Not me.
brewinistas enthusiasm notwithstanding, the homebrew package manager has growing pains typical of an immature package management solution. I use MacPorts to manage... all my installations, but also the various versions of ruby installations that are necessary to use the gems I want. MacPorts requires xcode, 5.1.1 is the most recent version for Mavericks. rvm uses MacPorts by default if it is installed.
It appears from your provided logs that you're missing stuff. That's what's nice about MacPorts (and any mature package manager); it takes care of the dependecies for you if they're not installed.
Install MacPorts
curl -Ok https://distfiles.macports.org/MacPorts/MacPorts-2.2.1.tar.bz2
tar xf MacPorts-2.2.1.tar.bz2
cd MacPorts-2.2.1
./configure
make
sudo make install
cd ..
rm -rf Macports-*
sudo /opt/local/bin/port -v selfupdate
add MacPorts to your $PATH:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
take a look at what MacPorts has for ruby
port search ruby |less
and/or just install nokogiri
sudo port -vsk install ruby19 libxml2 libxslt
sudo gem install nokogiri
port -vfp clean ruby19 libxml2 libxslt
if there's trouble try
sudo port upgrade outdated
MacPorts won't affect OS X version of anything, nor homebrew (except to make it superfluous) and keeps everything it installs in /opt making deinstallation a breeze (but this has nothing to do with where ruby keeps its gems, ~/.gem ). But you should really get to know and love MacPorts, it is your friend.
sudo port -dfp uninstall --follow-dependencies installed
sudo port -dfp uninstall all
sudo rm -rf /opt/local
sudo rm -rf /Library/Tcl/macports*