How to fix Nokogiri on Ubuntu?

江枫思渺然 提交于 2021-02-18 16:44:33

问题


I run Ubuntu 13.04 on my workstation with ruby 2.0.0, which was installed via RVM.

$ aptitude show libxml2

Package: libxml2
State: installed Automatically instlled: no Multi-Arch: same Version: 2.9.0+dfsg1-4ubuntu4.1

$ aptitude show libxml2-dev

Package: libxml2-dev
State: installed Automatically installed: no Multi-Arch: same Version: 2.9.0+dfsg1-4ubuntu4.1

$ aptitude show libxslt-dev

Package: libxslt1-dev
State: installed Automatically installed: no Version: 1.1.27-1ubuntu2 Priority: optional

$ nokogiri -v

WARNING: Nokogiri was built against LibXML version 2.9.0, but has dynamically loaded 2.8.0 # Nokogiri (1.6.0) --- warnings: - Nokogiri was built against LibXML version 2.9.0, but has dynamically loaded 2.8.0 nokogiri: 1.6.0 ruby: version: 2.0.0 platform: x86_64-linux description: ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux] engine: ruby libxml: binding: extension source: packaged libxml2_path: /home/pb/.rvm/gems/ruby-2.0.0-p195/gems/nokogiri-1.6.0/ports/x86_64-linux-gnu/libxml2/2.8.0 libxslt_path: /home/pb/.rvm/gems/ruby-2.0.0-p195/gems/nokogiri-1.6.0/ports/x86_64-linux-gnu/libxslt/1.1.26 compiled: 2.9.0 loaded: 2.8.0

I installed nokogiri with the command, because else it's using libxml2 version 2.8.0, but I'm not sure where it takes this from, since just libxml2 is installed via apt.

gem install nokogiri -- --with-xml2-include=/usr/include/libxml2/libxml --with-xslt-dir=/usr/include/libxslt

When I run my application I get the following error:

/home/pb/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in require': /home/pb/.rvm/gems/ruby-2.0.0-p195/gems/nokogiri-1.6.0/ports/x86_64-linux-gnu/libxml2/2.8.0/lib/libxml2.so.2: versionLIBXML2_2.9.0' not found (required by /home/pb/.rvm/gems/ruby-2.0.0-p195/gems/libxml-ruby-2.6.0/lib/libxml_ruby.so) - /home/pb/.rvm/gems/ruby-2.0.0-p195/gems/libxml-ruby-2.6.0/lib/libxml_ruby.so (LoadError)

Can anyone tell me how I get rid of libxml2 version 2.8.0?

Thanks


回答1:


Nokogiri is using its own version of libxml by default. Probably because Mac OS provides a version of libxml that is dated 2001 (!), and old libraries don't provide features Nokogiri depends on. However, this may cause a problem with the systems that are kept up-to-date. To resolve the problem you need to build Nokogiri against the libraries your OS provides.

This maybe something like this, it's from Arch Linux:

gem install nokogiri -- \
  --with-xml2-include=/usr/include/libxml2/libxml \
  --with-xml2-lib=/usr/lib \
  --with-xslt-include=/usr/include/libxslt \
  --with-xslt-lib=/usr/lib

You may need to install development packages if using distros like Ubuntu or Fedora. It should be libxml2-dev and libxslt1-dev on Ubuntu but correct me if I'm wrong.




回答2:


Ultimately, this is the only thing that worked for me on 14.04

gem uninstall nokogiri
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install # or use gem install instead



回答3:


Ran across your question researching an issue of my own. It looks like, for a time, the nokogiri team was overriding the system install of libxml at gem install time as indicated in this comment: https://github.com/sparklemotion/nokogiri/issues/829#issuecomment-16877522. Not sure if that helps you, but it seems relevant. Perhaps a new version of Nokogiri is in order.




回答4:


Try to reinstall it with system library.

gem install nokogiri -v 1.6.5 -- --use-system-libraries



来源:https://stackoverflow.com/questions/17468910/how-to-fix-nokogiri-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!