-->

libxml2 missing for nokogiri gem on Windows 8 x64

2020-08-09 11:38发布

问题:

What I found searching for similar issues was that Nokogiri does not yet have x64 support with Ruby 2.0. However although I'm on a Windows x64 machine my Ruby version is ruby 1.9.3p392 (2013-02-22) [i386-mingw32] from railsinstaller.org (with Rails 3.2.13). This also means DevKit is already installed.

gem install nokogiri --pre gives this error:

    Temporarily enhancing PATH to include DevKit...
    Building native extensions.  This could take a while...
    ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb
    checking for libxml/parser.h... no
    -----
    libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokog
    iri.html for help with installing dependencies.
    -----
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers.  Check the mkmf.log file for more
    details.  You may need configuration options.

    Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=C:/RailsInstaller/Ruby1.9.3/bin/ruby
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib=${xml2-dir}/lib

While gem install nokogiri --pre -- --with-xml2-lib --with-xslt-lib --platform=ruby raises this error:

    Temporarily enhancing PATH to include DevKit...
    Building native extensions.  This could take a while...
    ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb --with-xml2-lib --wi
    th-xslt-lib --platform=ruby
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers.  Check the mkmf.log file for more
    details.  You may need configuration options.

    Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=C:/RailsInstaller/Ruby1.9.3/bin/ruby
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib=${xml2-dir}/lib

    C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:1544:in `dir_config': undefin
    ed method `split' for true:TrueClass (NoMethodError)
    from extconf.rb:147:in `<main>'

I was unable to find a specific solution to any of this via SO/google groups/blogs/etc, is there one?

Here's my path:

    PATH=C:\RailsInstaller\Git\cmd;C:\RailsInstaller\Ruby1.9.3\bin;C:\windows;C:\win
    dows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files(
    x86)\Git\cmd;C:\Program Files\nodejs\;C:\cygwin\bin;C:\mingw64\x86_64-w64-mingw3
    2\bin;C:\mingw64\bin;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\gi
    t\cmd;C:\Users\Joshua\AppData\Roaming\npm;C:\mingw64\x86_64-w64-mingw32\bin;C:\P
    rogram Files\PostgreSQL\9.2\bin;

I have also tried downloading libxml2 from http://linux.softpedia.com/progDownload/libxml2-Download-162.html and placing the contents inside C:\RailsInstaller\Ruby1.9.3\lib as well as C:\RailsInstaller\DevKit\lib but I have received the same errors.

tl;dr there seem to be two different errors depending on the options I pass. The parser.h error and the TrueClass 'split' error.

回答1:

@Steve - There is a new version of nokogiri (1.6.2) that supports x64 Ruby (this worked for me on Win7 x64 Ruby 200). At time of writing it's in pre-release, install using:

 gem install nokogiri --prerelease


回答2:

I had a similar frustration, but I did just remove Ruby 2.0, and the DevKit that I had installed to keep things simple.

I then:

  • Installed 1.9.3
    (http://rubyforge.org/frs/download.php/76952/rubyinstaller-1.9.3-p429.exe)
  • DevKit (DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe)

And all is now working.

Do make sure you go through all the checks at: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit



回答3:

Here is how to install Nokogiri for Windows 8.1 x64 with Chocolatey, and DevKit x64.

https://stackoverflow.com/a/22210252/148844

cinst libxml2
cinst libxslt
cinst libiconv

gem install nokogiri -- --with-xml2-include=C:\Chocolatey\lib\libxml2.2.7.8.7\build\native\include --with-xml2-lib=C:\Chocolatey\lib\libxml2.redist.2.7.8.7\build\native\bin\v110\x64\Release\dynamic\cdecl --with-iconv-include=C:\Chocolatey\lib\libiconv.1.14.0.11\build\native\include --with-iconv-lib=C:\Chocolatey\lib\libiconv.redist.1.14.0.11\build\native\bin\v110\x64\Release\dynamic\cdecl --with-xslt-include=C:\Chocolatey\lib\libxslt.1.1.28.0\build\native\include --with-xslt-lib=C:\Chocolatey\lib\libxslt.redist.1.1.28.0\build\native\bin\v110\x64\Release\dynamic



回答4:

Just had this problem myself, it looks like Nokogiri does not support 64 bit Ruby: https://github.com/sparklemotion/nokogiri/issues/864 solution seems to be use 32 bit Ruby, that or wait until they support 64 bit Ruby.

Update: updated to reflect comment from @magiccrafter that 64 bit Ruby should now be supported.