Falla la instalación de Nokogiri-falta libxml2


Siempre he solucionado los problemas de instalación de Nokogiri siguiendo la documentación del tutorial " Installing Nokogiri".

Pero esta vez, incluso después de instalar todas las dependencias, Nokogiri no se ha instalado. Obtengo el siguiente error:

libxml2 is missing.  please visit <http://nokogiri.org/tutorials/installing_nokogiri.html>

Intenté instalarlo especificando los directorios libxml2 y libxslt:

sudo gem install nokogiri -- --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib --with-xslt-dir=/usr/

Pero devolvió el mismo error.

Seguí todos los demás artículos relacionados con Stack Overflow y ninguno ayudar. ¿Alguien tiene una solución?

Author: the Tin Man, 2011-06-08

19 answers

Primero, instale las dependencias:

sudo apt-get install libxslt-dev libxml2-dev

Si aún recibe el error, puede que le falte una cadena de herramientas del compilador:

sudo apt-get install build-essential

Obtendrá el error "falta libxml2" si le falta una cadena de herramientas de compilación (al menos me encontré con este problema en Debian Lenny).

La prueba de compilación Nokogiri-compila un archivo de encabezado libxml2 para verificar que está presente, sin embargo, no diferencia entre "falta libxml2" y "falta un compilador para probar libxml2".

 151
Author: Erik Peterson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 16:58:10

Es posible que necesite instalar ambos paquetes

sudo apt-get install libxslt-dev libxml2-dev
 243
Author: Ryan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-10-18 17:45:05

En Mac OS X (Mavericks), instalar las bibliotecas con brew y establecer NOKOGIRI_USE_SYSTEM_LIBRARIES=1 antes de instalar la gema hizo el truco para mí.

Resumiendo:

  • Si está instalado previamente, desinstale la gema:

    gem uninstall nokogiri
    
  • Use Homebrew para instalar libxml2, libxslt y libiconv:

    brew install libxml2 libxslt libiconv
    
  • Instale la gema especificando las rutas de acceso a las bibliotecas que se enlazarán:

    NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
    
 55
Author: eduardo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:13:01

Acabo de tener el mismo problema en Fedora 13. Después de una búsqueda frustrante y sin éxito para hacer

gem install nokogiri

Trabajo para mí, pude instalarlo y evitar el error libxml2 a través de yum.

Simplemente instale la gema a través de yum en lugar del comando gem:

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

Esto me ayudó a encontrar la respuesta correcta para Fedora y, como estoy usando RVM para la gestión de paquetes Ruby,

yum install rubygem-nokogiri

Introducirá todas las gemas y dependencias de Ruby en el sistema, no en mi RVM medio ambiente, y en mi experiencia que conduce a una experiencia muy frustrante y humilde.

Entonces, tomando tu hallazgo de la gema Nokogiri yum puedes usar:

yum provides  rubygem-nokogiri

Y obtener una lista de las dependencias para rubygem-Nokogiri que me mostró las bibliotecas que faltaban. Después de eso corrí:

yum install libxml2-devel libxslt libxslt-devel

Ahora Nokogiri compila en Fedora y Nokogiri instala. D'oh!, necesitamos las cabeceras para compilar Nokogiri de las bibliotecas de devel.

 21
Author: Sojoodi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:17:33

Normalmente necesitas archivos de desarrollo para construir gemas. Try:

sudo apt-get install libxslt-dev libxml2-dev

(Acabo de ver que Eric sugirió lo mismo en un comentario.)

 13
Author: pduersteler,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:13:53

En Mac OS X (Mavericks) si ninguna de estas soluciones funciona, intente:

ARCHFLAGS="-arch x86_64" gem install nokogiri

O

ARCHFLAGS="-arch i386" gem install nokogiri

Dependiendo de la arquitectura de su sistema.

 11
Author: rilla,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:09:49

Pude instalarlo con Chocolatey, Windows 8.1 x64 y 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

Tendrás que verificar que el número de versión en las rutas es correcto.

Es posible que necesite agregar el repositorio NuGet de Microsoft:

-Source "https://go.microsoft.com/fwlink/?LinkID=230477"
 11
Author: Chloe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:11:07

Será:

sudo yum install -y libxml2 libxml2-devel

En servidores RHEL.

 11
Author: hohner,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:14:04

Pude instalar Nokogiri 1.6.5 en Fedora 20 haciendo:

export NOKOGIRI_USE_SYSTEM_LIBRARIES=true

Luego se ejecuta:

gem install nokogiri
 4
Author: Simone,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-03 19:32:08

Para cualquier otra persona que experimente este problema, lo resolví ejecutando este comando dentro del directorio del proyecto

gem install nokogiri -- --use-system-libraries

Actualización: Me encontré con esto de nuevo e intenté simplemente actualizar la gema que funcionó para mí...

gem update nokogiri

 4
Author: Jbur43,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-28 16:31:01

En macOS ninguno de arriba/abajo realmente había funcionado para mí hasta que proporcioné explícitamente la ruta Xcode libxml2 a --with-xml2-include.

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2 --use-system-libraries
 3
Author: sobstel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-04 13:44:42

¿Ha intentado instalar libxml2? No desde rubygems, sino a través del proceso de instalación estándar para su sistema operativo. En Ubuntu / Debian por ejemplo:

sudo apt-get install libxml2

En cualquier versión reciente de OS X ya debería estar instalado.

 2
Author: d11wtq,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-08 10:53:28

Para los usuarios de OSX, si has tenido éxito instalando Nokogiri antes, sin embargo, están recibiendo errores al instalarlo, digamos, usando una nueva versión de Ruby que has agregado y ese error que incluye un mensaje como:

The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

Esto podría ser indicativo de una actualización de XCode que ha ocurrido a través de la App Store, ya sea manual o automáticamente, y que no la ha abierto desde entonces.

Si es así, debería poder abrir XCode, aceptar la nueva licencia y luego instalar Nokogiri con éxito.

 1
Author: Paul Fioravanti,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 16:59:13

En Mac OS X Yosemite mi error fue que intenté usar sudo gem install cuando es una regla general no usar privilegios de superusuario al instalar gemas.

En mi caso se trató de modificar la instalación del sistema de Ruby, y eso no es una buena idea. Instalé rbenv, instalé Ruby 2.2.2 a través de él y lo puse como global, que es un término de la documentación de rbenv. Después de eso Nokogiri podría instalarse con un simple

gem install nokogiri

No fueron necesarios hacks o soluciones alternativas, solo un conjunto adecuado medio ambiente; Nokogiri hace el resto perfectamente.

 1
Author: Aleks N.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:07:53

Fue capaz de instalar vagrant-awe siguiendo el post anterior, pero utilizando el comando de la siguiente manera:

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 vagrant plugin install vagrant-aws
 1
Author: Romi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:11:22

Para Windows x64:

gem inst nokogiri --pre --platform ruby

Para obtener más información, consulte este hilo: https://github.com/sparklemotion/nokogiri/issues/864

 1
Author: magiccrafter,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-16 09:48:14

Pude instalar Nokogiri ejecutando los siguientes paquetes:

$ dnf group install "C Development Tools and Libraries"
$ dnf install ruby-devel libxml2-devel patch
 0
Author: user1455180,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 16:59:27

= = = TLDR = = =

Como indican las instrucciones, compile Ruby con el último compilador de clang, o al menos la misma versión que Rubygems usará para compilar las extensiones nativas libxml y libxsl de Nokogiri.

Si se usa RVM, construir desde el origen con la bandera --with-ggc=clang fue lo que lo hizo por mí:

rvm install 2.2 --with-gcc=clang

Reemplace 2.2 con la versión que desee. --with-gcc=clang asegura que RVM se compila desde el código fuente y usa clang para hacerlo; de lo contrario, RVM puede tener un Ruby binario preconstruido, que es lo que me hizo tropezar.

Luego, instale Nokogiri como normal usando Bundler o Rubygems.

=== EN PROFUNDIDAD ===

Luché con esto por un tiempo. gem install nokogiri me dio:

checking for xmlParseDoc() in libxml/parser.h... no
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no

Cavando en mkmf.log Vi: {[13]]}

conftest.c:15:27: error: too few arguments to function call, single argument 'cur' was not specified
int t(void) { xmlParseDoc(); return 0; }  

Nokogiri suministra su propio libxml y libxsl (a partir de la versión 1.6.4). La firma definida en la copia local de Nokogiri de parser.h (se encuentra en el directorio de instalación de gem) es:

xmlParseDoc (const xmlChar *cur);                                                                                                                                                                                

Así que estaba en una pérdida en cuanto a cómo la llamada método en el conftest herméticamente sellado.el uso del archivo c no pudo coincidir con el archivo de cabecera para parser.h.

Cuando me di cuenta de que probablemente había instalado un Ruby binario, lo eliminé y reinstalé usando --with-gcc=clang (para forzar la compilación y usar clang) y el problema se resolvió:

rvm uninstall 2.2
rvm install 2.2 --with-gcc=clang
gem install nokogiri

No estoy exactamente seguro de por qué funciona ya que el encabezado libxml del sistema /usr/include/libxml2/libxml/parser.h tiene la misma firma que la copia local de Nokogiri.

Es raro, pero funcionó. Solo asegúrate de compilar un Ruby con clang.

 0
Author: Johnster,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:04:48
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

Cambie su versión con él.

 0
Author: Liber,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-02 17:10:10