我一直在試圖讓我的電腦(山獅)安裝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。如果任何人都可以幫我解決問題,我真的很感激。我一直沒有找到任何其他案例在線與這個問題。
'brew --prefix libxml2'的輸出是什麼?請參閱nokogiri/ext/nokogiri /中的extconf.rb文件,瞭解Nokogiri在哪裏查找庫和頭文件的線索。 – 2013-04-05 20:05:09
以下是輸出: /usr/local/opt/libxml2 我找到了你指的文件,我想我明白這是什麼意思,雖然我真的不確定。我應該添加從Homebrew到要檢查的位置列表的路徑嗎?如果我這樣做,將停止使用libxml2的舊版本,錯誤版本? – alexlafroscia 2013-04-05 21:10:20
你讀過_ [如果libxml2是一個混蛋怎麼辦](https://github.com/sparklemotion/nokogiri/wiki/What-to-do-if-libxml2-is-being-a-jerk)_ ? – Phrogz 2013-04-05 22:56:18