R "installation of package had non-zero exit status" in CI
install.packages compiled a package from source and the build exited non-zero. The summary line is generic; the real cause (a missing -dev header, a compiler error, or a missing system tool) is in the captured output above it.
What this error means
install.packages ends with "Warning message: In install.packages(...) : installation of package 'X' had non-zero exit status". On Linux this usually means a source build failed against missing system libraries.
* installing *source* package 'xml2' ...
Package libxml-2.0 was not found in the pkg-config search path.
ERROR: configuration failed for package 'xml2'
* removing '/usr/lib/R/site-library/xml2'
Warning message:
In install.packages("xml2") : installation of package 'xml2' had non-zero exit statusCommon causes
A missing system library for a source build
Packages with C bindings (xml2, curl, openssl, sf) need their -dev system libraries; a slim runner image omits them, so configure fails.
No binary available, so R compiles from source
On Linux, install.packages often builds from source by default, which needs a compiler and headers the image may not provide.
How to fix it
Install the system dependencies the package names
- Read the "was not found" or "fatal error" line in the build log.
- Install the matching
-devsystem package before R. - Re-run install.packages once the library is present.
sudo apt-get update
sudo apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-devInstall precompiled binaries from a binary repo
Use a binary package source (such as the Posit Public Package Manager) so no compiler or headers are needed.
Rscript -e 'install.packages("xml2", repos="https://packagemanager.posit.co/cran/__linux__/jammy/latest")'How to prevent it
- Install required
-devsystem libraries before install.packages. - Prefer a binary package repo in CI to skip source builds.
- Bake common system libraries into a custom runner image.