Nokogiri installation fails -libxml2 is missing

前端 未结 19 2313
情书的邮戳
情书的邮戳 2020-11-27 10:22

I always worked my way around Nokogiri installation issues by following the documentation in the \"Installing Nokogiri\" tutorial.

But this time, even after installi

相关标签:
19条回答
  • 2020-11-27 10:36
    gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
    

    Change your version with it.

    0 讨论(0)
  • 2020-11-27 10:38

    Have you tried installing libxml2? Not from rubygems, but via the standard install process for your operating system. On Ubuntu/Debian for example:

    sudo apt-get install libxml2
    

    On any recent version of OS X it should already be installed.

    0 讨论(0)
  • 2020-11-27 10:40

    First, install the dependencies:

    sudo apt-get install libxslt-dev libxml2-dev
    

    If you still receive the error, you may be missing a compiler toolchain:

    sudo apt-get install build-essential
    

    You'll get the "libxml2 is missing" error if you're missing a build toolchain (at least I ran into this issue on Debian Lenny).

    The Nokogiri build test-compiles a libxml2 header file to verify that it is present, however, it doesn't differentiate between "libxml2 is missing" and "a compiler to test libxml2 is missing".

    0 讨论(0)
  • 2020-11-27 10:41

    I was able to get this installed with Chocolatey, Windows 8.1 x64, and DevKit x64.

    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
    

    You'll have to verify the version number in the paths are correct.

    You may possibly need to add Microsoft's NuGet repository:

    -Source "https://go.microsoft.com/fwlink/?LinkID=230477"
    
    0 讨论(0)
  • 2020-11-27 10:42

    I just had the same issue on Fedora 13. After a frustrating and unsuccessful search to make

    gem install nokogiri
    

    work for me, I was able to install it and get around the libxml2 error via yum.

    Simply install the gem via yum instead of the gem command:

    su
    yum search rubygem-nokogiri   #this find the proper package name
    yum install rubygem-nokogiri.i686
    

    This helped me find the right answer for Fedora and, as I am using RVM for Ruby package management,

    yum install rubygem-nokogiri
    

    will pull in all the Ruby gems and dependencies into the system, not into my RVM environment, and in my experience that leads to a very frustrating and humbling experience.

    So, taking your find of the Nokogiri yum gem you can use:

    yum provides  rubygem-nokogiri
    

    and get a list of the dependencies for rubygem-Nokogiri which showed me the libraries that were missing. After that I ran:

    yum install libxml2-devel libxslt libxslt-devel
    

    Now Nokogiri compiles in Fedora and Nokogiri installs. D'oh!, we need the headers to compile Nokogiri from the devel libraries.

    0 讨论(0)
  • 2020-11-27 10:42

    In Mac OS X (Mavericks) if none of these solutions work, try:

    ARCHFLAGS="-arch x86_64" gem install nokogiri
    

    or

    ARCHFLAGS="-arch i386" gem install nokogiri
    

    depending on your system's architecture.

    0 讨论(0)
提交回复
热议问题