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.
Also Read: Elementary OS – Perfect Linux distribution to replace Windows and macOS
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.
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
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]
Also Read
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
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
....................................................
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;", 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.
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
........................................................
You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…
Have you ever found yourself staring at a terminal full of 404 errors while trying…
One particularly frustrating error that many users face when trying to upgrade from Ubuntu 18.04 …
In the world of containerization, time synchronization issues can create unexpected roadblocks when working with…
If you’ve recently upgraded to Ubuntu 23.04 or newer, you might have encountered a frustrating…
Canonical announces the General Availability of Ubuntu for the NVIDIA® Jetson Orin™ for edge AI…