Configuration failed to find libgit2 library

My builds started failing recently. I have devtools in my r_packages list. The build tries to install devtools, which depends on usethis, which depends on gert, which fails to install:

* installing *source* package ‘gert’ ...
** package ‘gert’ successfully unpacked and MD5 sums checked
** using staged installation
Using PKG_LIBS=-lgit2
----------------------------- ANTICONF -------------------------------
Configuration failed to find libgit2 library. Try installing:
 * brew: libgit2 (MacOS)
 * deb: libgit2-dev (Debian, Ubuntu, etc)
 * rpm: libgit2-devel (Fedora, CentOS, RHEL)
If libgit2 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libgit2.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] ---------------------------
<stdin>:1:18: fatal error: git2.h: No such file or directory
compilation terminated.
ERROR: configuration failed for package ‘gert’

I have a simple config:

language: r
cache: packages
warnings_are_errors: false

  - bioc-release
  - oldrel
  - release
  - devel

  - covr
  - devtools
  - tidyverse
  - shiny

  - Rscript -e 'library(covr); codecov()'

This is a fairly common package, but this does not seem to be a widespread problem. Why is this error happening for me?

If you’re linking against a C library, you need to install its development Apt package:

      - libgit2-dev

That makes sense, but I didn’t have to do that before and it doesn’t seem like other packages that you use devtools do that that either.

Maybe before, it happened to be preinstalled. In other topics, you can see plenty of cases where people install Apt development packages.


I also have the same issue when using R studio on Mac OS to install package “stopwords”, and the error message is exactly the same.

I’m not sure how to resolve it from reading this post, as I have no idea about R configuration and environment…