How to fix Nokogiri on Ubuntu?
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: version
LIBXML2_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
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.
最终,这是14.04年唯一对我有用的东西
gem uninstall nokogiri
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install # or use gem install instead
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.
链接地址: http://www.djcxy.com/p/61054.html