I was working on a new tool today where I ran into a little issue while running some tests using a Perl script in my Ubuntu box installed using Oracle Virtual Box.
Basically, the error displayed was “Can’t locate XML/LibXML.pm in @INC” and it looked like this:
Can’t locate XML/LibXML.pm in @INC (you may need to install the XML::LibXML module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at ./run_test.pl line 15.
BEGIN failed–compilation aborted at ./run_test.pl line 15.
As the error hinted on the solution, I tried installing LibXML Perl module using the command below:
sudo cpan install XML::LibXML
But this command ran into another trouble. The complete output is this:
Loading internal null logger. Install Log::Log4perl for logging messages
Reading ‘/home/abhi/.cpan/Metadata’
Database was generated on Thu, 23 Mar 2017 09:41:02 GMT
Running install for module ‘XML::LibXML’
Checksum for /home/abhi/.cpan/sources/authors/id/S/SH/SHLOMIF/XML-LibXML-2.0129.tar.gz ok
‘YAML’ not installed, will not store persistent state
Configuring S/SH/SHLOMIF/XML-LibXML-2.0129.tar.gz with Makefile.PL
enable native perl UTF8
running xml2-config…didn’t manage to get libxml2 config, guessing
options:
LIBS=’-L/usr/local/lib -L/usr/lib -lxml2 -lm’
INC=’-I/usr/local/include -I/usr/include’
If this is wrong, Re-run as:
$ /usr/bin/perl Makefile.PL LIBS=’-L/path/to/lib’ INC=’-I/path/to/include’Checking for ability to link against xml2…no
Checking for ability to link against libxml2…libxml2, zlib, and/or the Math library (-lm) have not been found.
Try setting LIBS and INC values on the command line
Or get libxml2 from
http://xmlsoft.org/
If you install via RPMs, make sure you also install the -devel
RPMs, as this is where the headers (.h files) are.Also, you may try to run perl Makefile.PL with the DEBUG=1 parameter
to see the exact reason why the detection of libxml2 installation
failed or why Makefile.PL was not able to compile a test program.
No ‘Makefile’ created SHLOMIF/XML-LibXML-2.0129.tar.gz
/usr/bin/perl Makefile.PL INSTALLDIRS=site — NOT OK
The fix is not very tricky but it might take some time to figure it out. In this quick tip, I’ll show you how to install LibXML module on Ubuntu or any other Linux distribution based on Ubuntu.
How to install LibXML Perl module on Ubuntu Linux
I have highlighted the reason for LibXML installation failure in the error output showed above. It is very clear in itself:
Checking for ability to link against libxml2…libxml2, zlib, and/or the Math library (-lm) have not been found.
Clearly the system is missing libxml2 and zlib libraries. To fix this issue all you need to do is to install the required libraries using the command below:
sudo apt-get install zlib1g-dev libxml2-dev
Once you installed thlibrarieses, go on and install LibXML Perl module in the regular fashion:
sudo cpan install XML::LibXML
That’s it. I hope this quick helped you to fix the tiny issues with installing LibXML module on Ubuntu 16.04 and other versions.