Cyberithub

How to Install libxml2-2.X.X on Linux [Simple Steps]

Advertisements

In this article, we will see how to install libxml2-2.X.X on Linux using few simple steps. libxml2 is a free and open source widely used software library for parsing XML (eXtensible Markup Language) documents. It is being developed as part of the GNOME project, but usable independently of this desktop environment. It provides a comprehensive set of functionalities to manipulate and navigate XML documents. libxml2 is written in C, making it highly portable and efficient, and it is available for a variety of operating systems including Linux. Here we will see how to install libxml2-2.X.X on Linux based systems in few simple steps.

 

Key Features

  • Parsing Capabilities: libxml2 can parse XML documents, including large and complex files, efficiently and correctly. It supports different parsing modes, such as tree-based and event-driven parsing.
  • Standards Compliance: The library adheres to various XML-related standards, including XML 1.0, Namespaces in XML, XML Base, and more. It aims to be fully conformant with the World Wide Web Consortium (W3C) specifications.
  • XPath Support: libxml2 provides support for XPath, a language used for navigating through elements and attributes in an XML document. This is particularly useful for extracting information from large XML files.
  • XSLT Support: Through integration with libxslt, another library from the GNOME project, libxml2 supports XSLT (eXtensible Stylesheet Language Transformations), which is used for transforming XML documents into other formats (like HTML, text, another XML, etc.).
  • DOM and SAX Interfaces: It offers both DOM (Document Object Model) and SAX (Simple API for XML) interfaces. DOM allows the entire document to be loaded into memory and navigated, while SAX provides a more memory-efficient event-driven approach.
  • Validation: libxml2 can validate XML documents against DTDs (Document Type Definitions) and XML Schemas, ensuring that the XML document adheres to specified formats and standards.
  • Performance and Portability: Known for its performance, libxml2 is also highly portable and can be used in various environments, from servers to embedded systems.

 

How to Install libxml2-2.X.X on Linux [Simple Steps]

How to Install libxml2-2.X.X on Linux [Simple Steps]

Also Read: Elementary OS - Perfect Linux distribution to replace Windows and macOS

Step 1: Prerequisites

a) You should have a running Linux Server.

b) You should have root or sudo access to run privileged commands.

c) You should have wget, make and tar utility available in your System.

 

 

Step 2: Update Your Server

Before installing any new packages, it is always recommended to check and install all the latest available updates in your System. If you are using Ubuntu/Debian based system, then use sudo apt update && sudo apt upgrade command as shown below.

sudo apt update && sudo apt upgrade

If you are using RHEL/CentOS/Fedora based systems then use either sudo yum update && sudo yum upgrade or sudo dnf update && sudo dnf upgrade command as shown below.

sudo yum update && sudo yum upgrade
sudo dnf update && sudo dnf upgrade

 

 

Step 3: Download libxml2-2.x.x

You have to first download the required libxml2 version from GNOME official website using wget utility as shown below. This will download the libxml2 tarball in current working directory.

cyberithub@ubuntu:~$ wget https://download.gnome.org/sources/libxml2/2.0/libxml2-2.0.0.tar.gz
--2024-01-22 02:25:56-- https://download.gnome.org/sources/libxml2/2.0/libxml2-2.0.0.tar.gz
Resolving download.gnome.org (download.gnome.org)... 151.101.1.91, 151.101.65.91, 151.101.129.91, ...
Connecting to download.gnome.org (download.gnome.org)|151.101.1.91|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://mirror.ossplanet.net/gnome/sources/libxml2/2.0/libxml2-2.0.0.tar.gz [following]
--2024-01-22 02:25:57-- https://mirror.ossplanet.net/gnome/sources/libxml2/2.0/libxml2-2.0.0.tar.gz
Resolving mirror.ossplanet.net (mirror.ossplanet.net)... 163.22.17.70, 2001:e10:6840:17::70
Connecting to mirror.ossplanet.net (mirror.ossplanet.net)|163.22.17.70|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 933330 (911K) [application/gzip]
Saving to: ‘libxml2-2.0.0.tar.gz’

libxml2-2.0.0.tar.gz 100%[============================================================================>] 911.46K 1.07MB/s in 0.8s

2024-01-22 02:25:58 (1.07 MB/s) - ‘libxml2-2.0.0.tar.gz’ saved [933330/933330]

 

 

Step 4: Extract tarball

Then extract the tarball using tar -xzf libxml2-2.0.0.tar.gz command as shown below. It will create a directory called libxml2-2.0.0 in current location and extract all the contents in it.

cyberithub@ubuntu:~$ tar -xzf libxml2-2.0.0.tar.gz

 

 

Step 5: Run Configure

Switch to libxml2-2.0.0 directory using cd libxml2-2.0.0 command as shown below.

cyberithub@ubuntu:~$ cd libxml2-2.0.0

To make system ready for installation, you have to run configure script as shown below. This script will check your system to determine if the necessary dependencies and environment settings are present to successfully compile and install the library package.

cyberithub@ubuntu:~/libxml2-2.0.0$ ./configure
loading cache ./config.cache
checking for a BSD compatible install... (cached) /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... (cached) yes
checking for working aclocal... found
checking for working autoconf... found
checking for working automake... found
checking for working autoheader... found
checking for working makeinfo... missing
checking for gcc... (cached) gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for a BSD compatible install... /usr/bin/install -c
checking how to run the C preprocessor... (cached) gcc -E
....................................................

 

 

Step 6: Compile Source Code

In the next step, you have to compile the source code by running make command as shown below. This utility will read the compilation instructions from the Makefile and generate the binaries.

cyberithub@ubuntu:~/libxml2-2.0.0$ make
make all-recursive
make[1]: Entering directory '/home/cyberithub/libxml2-2.0.0'
Making all in doc
make[2]: Entering directory '/home/cyberithub/libxml2-2.0.0/doc'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/cyberithub/libxml2-2.0.0/doc'
make[2]: Entering directory '/home/cyberithub/libxml2-2.0.0'
/bin/sh ./libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -I. -g -O2 -c SAX.c
mkdir .libs
gcc -DHAVE_CONFIG_H -I. -I. -I. -I. -g -O2 -c SAX.c -fPIC -DPIC -o .libs/SAX.lo
gcc -DHAVE_CONFIG_H -I. -I. -I. -I. -g -O2 -c SAX.c -o SAX.o >/dev/null 2>&1
mv -f .libs/SAX.lo SAX.lo
/bin/sh ./libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -I. -g -O2 -c entities.c
rm -f .libs/entities.lo
gcc -DHAVE_CONFIG_H -I. -I. -I. -I. -g -O2 -c entities.c -fPIC -DPIC -o .libs/entities.lo
entities.c: In function 'xmlEncodeEntitiesReentrant':
entities.c:912:28: warning: '__builtin___snprintf_chk' output may be truncated before the last format character [-Wformat-truncation=]
912 | snprintf(buf, 14, "&#x%X;", val);
....................................................

It is worth noting here that sometimes during compilation you might see an error like below and then compilation fails.

.....................................................
In file included from /usr/include/fcntl.h:301,
from nanohttp.c:49:
In function 'open',
inlined from 'xmlNanoHTTPSave' at nanohttp.c:1187:14:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:50:4: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
50 | __open_missing_mode ();
| ^~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [Makefile:308: nanohttp.lo] Error 1
make[2]: Leaving directory '/home/cyberithub/libxml2-2.0.0'
make[1]: *** [Makefile:448: all-recursive] Error 1
make[1]: Leaving directory '/home/cyberithub/libxml2-2.0.0'
make: *** [Makefile:678: all-recursive-am] Error 2

If this happens with you, then to fix this issue you need to open nanohttp.c under libxml2-2.X.X directory and add an argument 0777 in line no 1187 as highlighted below(could be different line number for you).

cyberithub@ubuntu:~/libxml2-2.0.0$ vi nanohttp.c
....................................
fd = open(filename, O_CREAT | O_WRONLY,0777);
....................................

Save and exit the file. Then run make command again. This time you will notice that error will be fixed and compilation will be completed successfully.

 

 

Step 7: Install libxml2-2.X.X

Once you have all the binaries generated, you can install them by using sudo make install command as shown below. This step will basically copy the compiled binaries, libraries, and other necessary files from the build directory to their designated locations on your system. This often includes copying files to system directories such as /usr/local/bin for executables or /usr/local/lib for libraries.

cyberithub@ubuntu:~/libxml2-2.0.0$ sudo make install
[sudo] password for cyberithub:
Making install in doc
make[1]: Entering directory '/home/cyberithub/libxml2-2.0.0/doc'
make[2]: Entering directory '/home/cyberithub/libxml2-2.0.0/doc'
make[2]: Nothing to be done for 'install-exec-am'.
/bin/sh ../mkinstalldirs /usr/local/share/gnome-xml/html/gnome-xml
mkdir /usr/local/share/gnome-xml
mkdir /usr/local/share/gnome-xml/html
mkdir /usr/local/share/gnome-xml/html/gnome-xml
/usr/bin/install -c -m 0644 ./xml.html ./structure.gif ./DOM.gif /usr/local/share/gnome-xml/html/gnome-xml
/usr/bin/install -c -m 0644 ./html/*.html /usr/local/share/gnome-xml/html/gnome-xml
/usr/bin/install -c -m 0644 ./html/index.sgml /usr/local/share/gnome-xml/html/gnome-xml
(cd ; gtkdoc-fixxref --module=gnome-xml --html-dir=/usr/local/share/gnome-xml/html)
/bin/sh: 1: gtkdoc-fixxref: not found
make[2]: [Makefile:259: install-data-local] Error 127 (ignored)
make[2]: Leaving directory '/home/cyberithub/libxml2-2.0.0/doc'
make[1]: Leaving directory '/home/cyberithub/libxml2-2.0.0/doc'
make[1]: Entering directory '/home/cyberithub/libxml2-2.0.0'
make[2]: Entering directory '/home/cyberithub/libxml2-2.0.0'
/bin/sh ./mkinstalldirs /usr/local/lib
........................................................

Leave a Comment