2013-04-05 39 views
6

我一直在試圖讓我的電腦(山獅)安裝Nokogiri與rspec和水豚一起使用,但對於我的生活,我無法讓它運行正常。獲取nokogiri使用更新版本的libxml2

從我可以告訴,問題是與nokogiri使用錯誤版本的libxml2。到目前爲止,我嘗試使用Homebrew卸載並重新安裝libxml2(確保它是最新的),使用bundle卸載並重新安裝nokogiri,並指定安裝nokogiri gem時安裝Homebrew的libxml2文件的確切路徑。我最近的安裝說明看起來像這樣

sudo gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 

其中所有這些位置都正確對應於安裝工具的位置。然而,在運行bundle exec rspec spec/requests/static_pages.rb,我仍然得到這樣的輸出:

/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `require': dlopen(/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/lib/libxml2.2.dylib (LoadError) 
Referenced from: /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle 
Reason: Incompatible library version: nokogiri.bundle requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0 - /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle 
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `<top (required)>' 
    from /Users/alex/.rvm/gems/[email protected]/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require' 
    from /Users/alex/.rvm/gems/[email protected]/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require' 
    from /Users/alex/.rvm/gems/[email protected]/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each' 
    from /Users/alex/.rvm/gems/[email protected]/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require' 
    from /Users/alex/.rvm/gems/[email protected]/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each' 
    from /Users/alex/.rvm/gems/[email protected]/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require' 
    from /Users/alex/.rvm/gems/[email protected]/gems/bundler-1.3.4/lib/bundler.rb:132:in `require' 
    from /Users/alex/Sites/harbingernews/config/application.rb:7:in `<top (required)>' 
    from /Users/alex/Sites/harbingernews/config/environment.rb:2:in `require' 
    from /Users/alex/Sites/harbingernews/config/environment.rb:2:in `<top (required)>' 
    from /Users/alex/Sites/harbingernews/spec/spec_helper.rb:3:in `require' 
    from /Users/alex/Sites/harbingernews/spec/spec_helper.rb:3:in `<top (required)>' 
    from /Users/alex/Sites/harbingernews/spec/requests/static_pages_spec.rb:1:in `require' 
    from /Users/alex/Sites/harbingernews/spec/requests/static_pages_spec.rb:1:in `<top (required)>' 
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load' 
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files' 
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map' 
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files' 
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run' 
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run' 
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun' 

我已經嘗試了所有,我已經在網上找到的步驟(最參考構建和加載不同版本的libxml2的,像this one,但暫時還沒有我的Gemfile和Gemfile.lock可以找到here。如果任何人都可以幫我解決問題,我真的很感激。我一直沒有找到任何其他案例在線與這個問題。

+0

'brew --prefix libxml2'的輸出是什麼?請參閱nokogiri/ext/nokogiri /中的extconf.rb文件,瞭解Nokogiri在哪裏查找庫和頭文件的線索。 – 2013-04-05 20:05:09

+0

以下是輸出: /usr/local/opt/libxml2 我找到了你指的文件,我想我明白這是什麼意思,雖然我真的不確定。我應該添加從Homebrew到要檢查的位置列表的路徑嗎?如果我這樣做,將停止使用libxml2的舊版本,錯誤版本? – alexlafroscia 2013-04-05 21:10:20

+1

你讀過_ [如果libxml2是一個混蛋怎麼辦](https://github.com/sparklemotion/nokogiri/wiki/What-to-do-if-libxml2-is-being-a-jerk)_ ? – Phrogz 2013-04-05 22:56:18

回答

4

只是爲了說清楚,Phrogz的評論幫了我很大的忙,我按照他所鏈接的說明,在Nokogiri的Github頁面上登錄What to do if libxml2 is being a jerk?頁面。 p使用Macports而不是Homebrew,我不確定這是否是造成差異的原因(我已經嘗試了許多這些步驟),但無論如何,它現在似乎仍然行得通。

+3

嗯,我希望看到一個自制解決方案。 – fatuhoku 2014-05-23 19:34:18

9

在安裝gem之前,在小牛隊中,安裝庫brew和設置NOKOGIRI_USE_SYSTEM_LIBRARIES=1對我來說確實是個訣竅。

彙總:

  • 如果以前安裝,卸載寶石:
    $ gem uninstall nokogiri

  • 使用自制安裝libxml2libxsltlibiconv
    $ brew install libxml2 libxslt libiconv

  • 安裝寶石指定pa部份的圖書館對鏈接:
    $ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

1

Google搜索這個問題升級OSX,當我有問題後:

require': dlopen(/Users/tomi/.rvm/gems/[email protected]/extensions/x86_64-darwin-12/2.1.0-static/nokogiri-1.5.10/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/opt/libxml2/lib/libxml2.2.dylib (LoadError)

,這爲我工作

brew uninstall libxml2 libxslt libiconv brew install libxml2 libxslt libiconv

+0

在OS X上運行'install'命令時輸出小牛: '''錯誤:沒有可用的libiconv公式 Apple通過OS X分發libiconv,您可以在/ usr/lib中找到它。 一些構建腳本無法正確檢測到它,請檢查現有的 公式的解決方案.''' – Webdevotion 2014-08-25 14:03:44

8

這可以幫助我更新l ibxml並正確安裝nokogiri ...

  1. 寶石卸載的libxml引入nokogiri - 紅寶石
  2. 釀造更新
  3. 釀造卸載libxml2的
  4. 釀造安裝的libxml2 --with-XML2-配置
  5. 釀造環節--force libxml2的
  6. 釀造安裝libxslt
  7. brew鏈接 - 強制libxslt
  8. 捆綁配置build.nokogiri - --with-xml2- DIR =/USR --with-XSLT-DIR = /選擇/本地--with-的iconv-DIR = /選擇/本地
  9. 束安裝

這裏是源:http://www.kormoc.com/2013/12/22/nokogiri-libxml2/

希望這有助於某人...

+0

它爲我工作:)謝謝 – 2014-12-23 13:14:16

+0

不幸的是在OS X 10.10.5不工作(不過仍然抱怨libxml2。 – 2015-10-07 06:58:48

相關問題