35

I may have taken one step too far beyond my knowledge. I installed Homebrew and after it continued to give me warnings about having MacPorts installed I uninstalled that. But now my rspec tests don't run.

These are the errors I get:

/Users/mark/.rvm/gems/ruby-1.9.2-p180/gems/nokogiri-1.4.4/lib/nokogiri.rb:13:in `require': dlopen(/Users/mark/.rvm/gems/ruby-1.9.2-p180/gems/nokogiri-1.4.4/lib/nokogiri/nokogiri.bundle, 9): Library not loaded: /opt/local/lib/libiconv.2.dylib (LoadError)
  Referenced from: /Users/mark/.rvm/gems/ruby-1.9.2-p180/gems/nokogiri-1.4.4/lib/nokogiri/nokogiri.bundle
  Reason: Incompatible library version: nokogiri.bundle requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0 - /Users/mark/.rvm/gems/ruby-1.9.2-p180/gems/nokogiri-1.4.4/lib/nokogiri/nokogiri.bundle
.....
.....

I've installed libiconv through Homebrew, but that didn't fix it. It's complaining about libiconv version numbers. Is this the problem?

What is going on here and what do I need to do?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
markstewie
  • 9,237
  • 10
  • 50
  • 72

4 Answers4

83

I got things working again for anyone interested. I removed and re-installed nokogiri gem and everything seems to be working again.

markstewie
  • 9,237
  • 10
  • 50
  • 72
15

Generally, this problem is caused by being unable to find the right libiconv. Here is how I solve my problem:

Check output of otool -L /usr/lib/libiconv.2.dylib. I got the following output:

/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

Then I install libiconv with Homebrew, brew install libiconv, and show where it was installed using brew list libiconv. I got the following output:

/usr/local/Cellar/libiconv/1.14/bin/iconv
/usr/local/Cellar/libiconv/1.14/include/ (3 files)
/usr/local/Cellar/libiconv/1.14/lib/libcharset.1.dylib
/usr/local/Cellar/libiconv/1.14/lib/libiconv.2.dylib
/usr/local/Cellar/libiconv/1.14/lib/ (3 other files)
/usr/local/Cellar/libiconv/1.14/share/doc/ (6 files)
/usr/local/Cellar/libiconv/1.14/share/man/ (6 files)

the libiconv is installed in /usr/local/Cellar/libiconv/1.14/lib/libiconv.2.dylib. Then I check verion of newly installed libiconv, otool -L /usr/local/Cellar/libiconv/1.14/lib/libiconv.2.dylib, and I got the following output:

/usr/local/Cellar/libiconv/1.14/lib/libiconv.2.dylib:
/usr/local/opt/libiconv/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

The version is correct, and we need to make this library available for Ruby. Creating a symbol link is a quick solution:

sudo ln -s /usr/local/opt/libiconv/lib/libiconv.2.dylib /opt/local/lib/libiconv.2.dylib
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nicholas Ren
  • 263
  • 2
  • 8
  • 8
    I think you can replace the last step by: `brew link --force libiconv` Anyhow, your answer is a very nice solution since it doesn't involve reinstalling nokogiri. – sybohy Feb 11 '13 at 21:03
  • Thanks for this! Helped me immensely! I'm not sure for everyone, but I needed to add `brew tap homebrew/dupes` before brew found the `libiconv` formula. – Indranil Jan 22 '14 at 01:40
0

I had to re-install libxml-ruby in addition to nokogiri to get things working again.

jan
  • 1,160
  • 1
  • 9
  • 11
0

FWIW, I ran into the same issue and if you are vendorizing your gems, you will have to remove the offending gem from vendor/ruby as a gem uninstall + reinstall is not always efficient. I'm guessing bundler leaves cache remnants of gems and their respective libs even when running a fresh install.

random-forest-cat
  • 33,652
  • 11
  • 120
  • 99