Skip to content
Latchkey

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.

R
* 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 status

Common 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

  1. Read the "was not found" or "fatal error" line in the build log.
  2. Install the matching -dev system package before R.
  3. Re-run install.packages once the library is present.
Terminal
sudo apt-get update
sudo apt-get install -y libxml2-dev libcurl4-openssl-dev libssl-dev

Install 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.

Terminal
Rscript -e 'install.packages("xml2", repos="https://packagemanager.posit.co/cran/__linux__/jammy/latest")'

How to prevent it

  • Install required -dev system libraries before install.packages.
  • Prefer a binary package repo in CI to skip source builds.
  • Bake common system libraries into a custom runner image.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →