Upgrading Libxml2 on CentOS 5.8 fixes Libxmljs
Wednesday, 25th July 2012, 11:33
Another day, another diatribe on the frustrations of CentOS 5.8, well okay maybe not quite that bad. In fact, more of another how to fix something which is broken because CentOS packages are out of date, which wouldn't be an issue if you could easily migrate to the next major version like you can with OpenBSD, but I digress.
So, for a while now, the Node.js module Libxmljs has relied on a later version of Libxml2 than CentOS 5.8 ships with, when you build it errors like the following show up:
Waf: Entering directory /node_modules/libxmljs/build'
[ 1/10] cxx: src/libxmljs.cc -> build/Release/src/libxmljs_1.o
cc1plus: warnings being treated as errors
/usr/local/include/node/ev-emul.h: In function ‘void __ev_timer_start(__ev_timer*)’:
/usr/local/include/node/ev-emul.h:203: warning: passing ‘double’ for argument 3 to ‘int uv_timer_start(uv_timer_t*, void (*)(uv_timer_t*, int), int64_t, int64_t)’
/usr/local/include/node/ev-emul.h:203: warning: passing ‘double’ for argument 4 to ‘int uv_timer_start(uv_timer_t*, void (*)(uv_timer_t*, int), int64_t, int64_t)’
Waf: Leaving directory/node_modules/libxmljs/build'
Or maybe even this:
Waf: Entering directory /root/nLocate/node_modules/libxmljs/build'
[ 1/10] cxx: src/libxmljs.cc -> build/default/src/libxmljs_1.o
[ 2/10] cxx: src/xml_attribute.cc -> build/default/src/xml_attribute_1.o
[ 3/10] cxx: src/xml_document.cc -> build/default/src/xml_document_1.o
[ 4/10] cxx: src/xml_element.cc -> build/default/src/xml_element_1.o
cc1plus: warnings being treated as errors
../src/xml_element.cc: In static member function ‘static v8::Handle libxmljs::XmlElement::ChildNodes(const v8::Arguments&)’:
../src/xml_element.cc:207: warning: passing ‘double’ for argument 1 to ‘v8::Handle libxmljs::XmlElement::get_child(int32_t)’
[ 5/10] cxx: src/xml_namespace.cc -> build/default/src/xml_namespace_1.o
../src/xml_namespace.cc: In constructor ‘libxmljs::XmlNamespace::XmlNamespace(xmlNs*)’:
../src/xml_namespace.cc:67: error: ‘struct _xmlNs’ has no member named ‘context’
../src/xml_namespace.cc:70: error: ‘struct _xmlNs’ has no member named ‘context’
../src/xml_namespace.cc: In destructor ‘virtual libxmljs::XmlNamespace::~XmlNamespace()’:
../src/xml_namespace.cc:79: error: ‘struct _xmlNs’ has no member named ‘context’
../src/xml_namespace.cc:82: error: ‘struct _xmlNs’ has no member named ‘context’
Waf: Leaving directory/root/nLocate/node_modules/libxmljs/build'
In fact, generally, if you npm install libxmljs and get any sort of error that reads similar to the above, run the following command and see what version of Libxml2 you are actually running:
prompt# xml2-config --version
If it says 2.6.x then there is a very good chance this is where your problem lies, and no amount of yum updating is going to fix it.
Installing Libxml2 from RPM
This method is a little more involved, but it definitely works. I didn't come up with it, I found it on serverfault.com posted by Chad Feller.
The steps required are as follows. Firstly, install the CentOS development tools which include various packages you will need to make RPMs.
prompt# cd /home/somewhere_to_store_it
prompt# yum groupinstall "Development Tools"
prompt# yum install python-devel
prompt# wget http://xmlsoft.org/sources/libxml2-2.7.8-1.src.rpm
Now these next command apparently build the RPM, but it isn't signed so you will get warnings about that.
prompt# rpm -ivh libxml2-2.7.8-1.src.rpm --nomd5
prompt# rpmbuild -ba /usr/src/redhat/SPECS/libxml2.spec
It's quite possible if you are missing dependencies that you'll need to yum install them, but I didn't, and I suspect it won't contain anything that the older Libxml2 version didn't already need. If you do, then you'll need to install those and re-run the above rpmbuild command.
Now what follows requires you to know what archicture your server uses, for me it is the following for my test 32-bit server that runs under a VM:
prompt# yum localinstall --nogpgcheck /usr/src/redhat/RPMS/i386/libxml2-2.7.8-1.i386.rpm
prompt# yum localinstall --nogpgcheck /usr/src/redhat/RPMS/i386/libxml2-python-2.7.8-1.i386.rpm
prompt# yum localinstall --nogpgcheck /usr/src/redhat/RPMS/i386/libxml2-devel-2.7.8-1.i386.rpm
And for my 64bit live server:
prompt# yum localinstall --nogpgcheck /usr/src/redhat/RPMS/x86_64/libxml2-2.7.8-1.x86_64.rpm
prompt# yum localinstall --nogpgcheck /usr/src/redhat/RPMS/x86_64/libxml2-python-2.7.8-1.x86_64.rpm
prompt# yum localinstall --nogpgcheck /usr/src/redhat/RPMS/x86_64/libxml2-devel-2.7.8-1.x86_64.rpm
Chances are, if your architecture doesn't match the above, you can find the newly made libxml2 files somewhere under /usr/src/redhat/RPMS/ with a bit of a hunt.
Installing Libxml2 from Source
I seem to have actually managed this myself, so it must work. The problem is I'm not entirely sure exactly what I did, beyond downloading, running a standard ./configure, and then make/make installing.
So in theory it should work, just download libxml2-2.7.8 from the following URL and give it a go: ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz
Libxmljs
This should now work, just to make sure, though, remove the directory and run the npm install command.
prompt# npm install libxmljs