I have tried installing nokogiri on my rvm ruby 2.0.0-p353 using both homebrew and macports following instructions on the nokogiri installation page found here:
http://nokogiri.org/tutorials/installing_nokogiri.html
In both, I get exactly the same error message of bad file descriptor as shown below:
→ sudo gem install nokogiri
Fetching: mini_portile-0.5.2.gem (100%)
Successfully installed mini_portile-0.5.2
Fetching: nokogiri-1.6.1.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb
/Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:292:in `initialize_copy': Bad file descriptor (Errno::EBADF)
from /Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:292:in `initialize_dup'
from /Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:292:in `dup'
from /Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:292:in `<module:Logging>'
from /Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:289:in `<module:MakeMakefile>'
from /Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:47:in `<top (required)>'
from /Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/Bharat/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from extconf.rb:5:in `<main>'
extconf failed, exit code 1
Searching on this error turns up very little information related to jRuby but I am using MRI.