Problems when installing R packages on GNU/Linux

R
Teaching
Installation
Packages
Author

Johannes Titz

Published

April 20, 2023

In our R courses, it occasionally happens that students encounter problems when installing packages. This occurs most often under GNU/Linux, where system dependencies can be difficult to handle. There are so many different Linux distributions that dependencies cannot always be managed automatically.

What do typical errors look like? Just recently, a good example came in via OPAL, where a student attempted to install the package DescTools. The installation failed with the following message:

> install.packages("DescTools")
Installing package into ‘/afs/tu-chemnitz.de/home/urz/f/fasic/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘curl’, ‘httr’

versuche URL 'https://cloud.r-project.org/src/contrib/curl_5.0.0.tar.gz'
Content type 'application/x-gzip' length 682047 bytes (666 KB)
==================================================
  downloaded 666 KB

versuche URL 'https://cloud.r-project.org/src/contrib/httr_1.4.5.tar.gz'
Content type 'application/x-gzip' length 160874 bytes (157 KB)
==================================================
  downloaded 157 KB

versuche URL 'https://cloud.r-project.org/src/contrib/DescTools_0.99.48.tar.gz'
Content type 'application/x-gzip' length 2635756 bytes (2.5 MB)
==================================================
  downloaded 2.5 MB

* installing *source* package ‘curl’ ...
** Paket ‘curl’ erfolgreich entpackt und MD5 Summen überprüft
** using staged installation
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Using PKG_CFLAGS=
  Using PKG_LIBS=-lcurl
--------------------------- [ANTICONF] --------------------------------
  Configuration failed because libcurl was not found. Try installing:
  * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
* rpm: libcurl-devel (Fedora, CentOS, RHEL)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
  R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
  :1:10: fatal error: curl/curl.h: Datei oder Verzeichnis nicht gefunden
compilation terminated.
--------------------------------------------------------------------
  ERROR: configuration failed for package ‘curl’
* removing ‘/afs/tu-chemnitz.de/home/urz/f/fasic/R/x86_64-pc-linux-gnu-library/4.0/curl’
Warning in install.packages :
  installation of package ‘curl’ had non-zero exit status
ERROR: dependency ‘curl’ is not available for package ‘httr’
* removing ‘/afs/tu-chemnitz.de/home/urz/f/fasic/R/x86_64-pc-linux-gnu-library/4.0/httr’
Warning in install.packages :
  installation of package ‘httr’ had non-zero exit status
ERROR: dependency ‘httr’ is not available for package ‘DescTools’
* removing ‘/afs/tu-chemnitz.de/home/urz/f/fasic/R/x86_64-pc-linux-gnu-library/4.0/DescTools’
Warning in install.packages :
  installation of package ‘DescTools’ had non-zero exit status

The downloaded source packages are in
‘/tmp/RtmpJh9T8H/downloaded_packages’

Pretty cryptic, right?
Definitely—but if you take a closer look, the actual problem becomes clear:

Configuration failed because libcurl was not found. Try installing:
  * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
  * rpm: libcurl-devel (Fedora, CentOS, RHEL)

So a system package is missing, namely libcurl. On Debian-based systems, the package is called libcurl4-openssl-dev, and it can typically be installed like this:

apt-get install libcurl4-openssl-dev

On other systems, the package name may differ and must be installed using the appropriate package manager. For Fedora and related distributions, the package is called libcurl-devel.

In most cases, installation problems can be resolved this way. As always, the rule is: read the error message carefully—it usually tells you exactly what to do.

What if you don’t have root privileges?

Of course, you could also install the required libraries locally and then extend the $PATH variable (more on this perhaps in a future blog post). At our computing center (URZ), however, it is usually no problem to request that system packages be installed.

To avoid repeatedly bothering the administrators, it is helpful to determine in advance whether there are additional dependencies. The easiest way to do this is with the remotes package:

remotes::system_requirements("ubuntu-18.04", package = "DescTools")
[1] "apt-get install -y libx11-dev"          
[2] "apt-get install -y libcurl4-openssl-dev"
[3] "apt-get install -y libssl-dev"          
[4] "apt-get install -y make"                
[5] "apt-get install -y zlib1g-dev"          

Here, we simply specified Ubuntu as the system, since its dependencies largely overlap with Debian.
Now you can just send an email to the URZ listing the required packages, and installing DescTools should no longer be a problem.