Errors using rspec, missing libraries after installing Homebrew and uninstalling MacPorts

5.9k Views Asked by At

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?

4

There are 4 best solutions below

4
On BEST ANSWER

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

0
On

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

2
On

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
0
On

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.