24

I am trying to install devtools in R version 3.2.1, however when I do the following error is thrown:

Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing libxml-2.0.pc
to the PKG_CONFIG_PATH environment variable

when I run dpkg -L libxml2-dev in a terminal I find:

/usr
/usr/bin
/usr/bin/xml2-config
/usr/share
/usr/share/aclocal
/usr/share/aclocal/libxml2.m4
/usr/share/doc
/usr/share/doc/libxml2-dev
/usr/share/doc/libxml2-dev/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/xml2-config.1.gz
/usr/share/man/man3
/usr/share/man/man3/libxml.3.gz
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libxml2.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/libxml-2.0.pc
/usr/lib/x86_64-linux-gnu/xml2Conf.sh
/usr/include
/usr/include/libxml2
/usr/include/libxml2/libxml
/usr/include/libxml2/libxml/globals.h
/usr/include/libxml2/libxml/schematron.h
/usr/include/libxml2/libxml/xlink.h
/usr/include/libxml2/libxml/HTMLparser.h
/usr/include/libxml2/libxml/pattern.h
/usr/include/libxml2/libxml/xmlexports.h
/usr/include/libxml2/libxml/xmlschemas.h
/usr/include/libxml2/libxml/list.h
/usr/include/libxml2/libxml/entities.h
/usr/include/libxml2/libxml/xmlstring.h
/usr/include/libxml2/libxml/encoding.h
/usr/include/libxml2/libxml/hash.h
/usr/include/libxml2/libxml/xmlmemory.h
/usr/include/libxml2/libxml/relaxng.h
/usr/include/libxml2/libxml/xmlsave.h
/usr/include/libxml2/libxml/SAX2.h
/usr/include/libxml2/libxml/xmlIO.h
/usr/include/libxml2/libxml/xmlschemastypes.h
/usr/include/libxml2/libxml/xpathInternals.h
/usr/include/libxml2/libxml/schemasInternals.h
/usr/include/libxml2/libxml/xmlmodule.h
/usr/include/libxml2/libxml/valid.h
/usr/include/libxml2/libxml/c14n.h
/usr/include/libxml2/libxml/xmlwriter.h
/usr/include/libxml2/libxml/tree.h
/usr/include/libxml2/libxml/xmlunicode.h
/usr/include/libxml2/libxml/nanohttp.h
/usr/include/libxml2/libxml/catalog.h
/usr/include/libxml2/libxml/xmlerror.h
/usr/include/libxml2/libxml/nanoftp.h
/usr/include/libxml2/libxml/xmlautomata.h
/usr/include/libxml2/libxml/xinclude.h
/usr/include/libxml2/libxml/HTMLtree.h
/usr/include/libxml2/libxml/chvalid.h
/usr/include/libxml2/libxml/parserInternals.h
/usr/include/libxml2/libxml/xpointer.h
/usr/include/libxml2/libxml/xmlversion.h
/usr/include/libxml2/libxml/dict.h
/usr/include/libxml2/libxml/xmlregexp.h
/usr/include/libxml2/libxml/DOCBparser.h
/usr/include/libxml2/libxml/parser.h
/usr/include/libxml2/libxml/xmlreader.h
/usr/include/libxml2/libxml/SAX.h
/usr/include/libxml2/libxml/threads.h
/usr/include/libxml2/libxml/debugXML.h
/usr/include/libxml2/libxml/xpath.h
/usr/include/libxml2/libxml/uri.h
/usr/share/doc/libxml2-dev/README
/usr/share/doc/libxml2-dev/NEWS.gz
/usr/share/doc/libxml2-dev/AUTHORS
/usr/share/doc/libxml2-dev/TODO.gz
/usr/share/doc/libxml2-dev/changelog.Debian.gz
/usr/lib/x86_64-linux-gnu/libxml2.so

to try and add this to the PKG_CONFIG_PATH I tried: env PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig however this does not seem to work.

mattbawn
  • 1,358
  • 2
  • 13
  • 33
  • You only get these two lines when your run `dpkg -L libxml2-dev`? If yes, `libxml2` is probably not installed. –  Aug 03 '15 at 22:33
  • @Pascal, No There are more I just added the two that seemed pertinent. I have added the full output from the call now for clarity. – mattbawn Aug 04 '15 at 15:18

7 Answers7

32

OK so in the end I had to manually install libxml2 even though my system said it allready had the most up to date version installed after: sudo apt-get install libxml2 libxml2-dev

I manually installed based on info found here:

wget ftp://xmlsoft.org/libxml2/libxml2-2.9.2.tar.gz

Then uppack to a directory, e.g.:

tar -xvf libxml2-2.9.2.tar.gz
cd libxml2-2.9.2

Configure the install:

./configure --prefix=/usr --disable-static --with-history && make

and

sudo make install

after this the R command install.packages("devtools") completed with success.

Tomas Votruba
  • 23,240
  • 9
  • 79
  • 115
mattbawn
  • 1,358
  • 2
  • 13
  • 33
  • Good to know. There is either a Debian/Ubuntu bug here, and/or a bug with the xml2 package. In either case you should really not change `/usr/local` to `/usr` as you now continue to mix local installations with package installations. That is generally a bad idea ... – Dirk Eddelbuettel Aug 04 '15 at 20:55
  • This worked for me on Ubuntu 18.04 without doing anything after the `wget` step – AmirY Oct 05 '20 at 22:45
11

Choose and Install suitable library from below as per your Linux flavor:-

  • deb: libxml2-dev (Debian, Ubuntu, etc)
  • rpm: libxml2-devel (Fedora, CentOS, RHEL)
  • csw: libxml2_dev (Solaris)

Install with an appropriate command like apt-get, yum, etc.

saurabh gupta
  • 491
  • 6
  • 18
  • 1
    Please note you might still get an error due to `libxml2-dev` not being installed properly if you go the `apt-get, yum, etc.` way. What worked for me on Ubuntu 18.04 was the command `wget ftp://xmlsoft.org/libxml2/libxml2-2.9.2.tar.gz` as @mattbawn suggested above – AmirY Oct 05 '20 at 22:53
  • Thank you, this fixed a `pip` issue for me. Much better than manually building from source. – rjh Oct 16 '22 at 00:49
6

From within R prompt, this command works provided that libxml2-dev has been installed:

Sys.setenv(PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig")
biocyberman
  • 5,675
  • 8
  • 38
  • 50
  • 1
    My specific problem seemed to be an issue with my system not recognising the configuration of libxml2-dev but +1 for the tip! – mattbawn Aug 07 '15 at 19:20
  • 1
    I had the same problem. I tried this first before trying to install libxml2-dev manually, it helps – biocyberman Aug 07 '15 at 23:17
2

For the narrower problem of installing the R package "XML", just do

 sudo apt-get install r-cran-xml

Otherwise, start at the list of dependencies for "devtools" (eg from here) and install these dependencies one by one.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks for the answer but I think I'm missing something. If I do this and try again to install devtools the installation still fails with the same error. `* installing *source* package ‘xml2’ ... ** package ‘xml2’ successfully unpacked and MD5 sums checked Package libxml-2.0 was not found in the pkg-config search path. Perhaps you should add the directory containing libxml-2.0.pc' to the PKG_CONFIG_PATH environment variable`. Can you clarity for me please? – mattbawn Aug 04 '15 at 16:31
  • Sorry, so it is package `xml2`, not package `XML` and the binary won't help you. My recommendation of installation dependencies one by one and checking _their individual error logs_ still stands. All those packages install just fine on all my Ubuntu machines ... – Dirk Eddelbuettel Aug 04 '15 at 16:56
1

I had this problem on Fedora 31 (as of Apr 2020; error in xml2 installation). Installing libxml2-devel seems to solve it for me.

$ dnf install libxml2-devel

Anas sheshai
  • 375
  • 1
  • 4
  • Thanks, I was having issues installing tidyverse on MX Linux and this was one of the packages I was missing but the error message didn't mention libxml2-devel. – Andrew Borst Feb 19 '22 at 00:17
0

Today, 4 years and 2 months later, I was having exactly the same issue (even if in the context of the installation of a different package, xml2).

Looking closely at the .configure script of the package, I noticed that following one-line configuration test was failing:

echo "#include $PKG_TEST_HEADER" | ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E -xc - >/dev/null 2>&1 || R_CONFIG_ERROR=1;

This is despite all the used parameters having correct and non-null values.

I'm not sure why exactly this test fails, but it seems to be a bug (so Dirk Eddelbuettel was right). Commenting out the test, allowed me to manually install the package without any further issues.

Vincent
  • 2,073
  • 1
  • 17
  • 24
0

if you used conda env R, then use conda to resolve this problem.

conda install -c anaconda libxml2

upuil
  • 67
  • 2
  • 8