Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running install.packages("usethis") results in "fatal error: 'git2.h' file not found". #1970

Closed
markariosd3 opened this issue Apr 2, 2024 · 3 comments

Comments

@markariosd3
Copy link

This issue appears very similar to this one written about on March 29, 2021 #1410 (comment) but I'm not doing anything with Github Actions, I'm just trying to install usethis. Based on the 2021 issue it appears that I should install libgit2 as the other advice of waiting for a new cran build doesn't make sense since the R version Angel Food Cake would have correct this error. I also pasted my console below. Can someone please kindly give me a clue on how to get past this?

Lastly, I'm sorry in advance if this isn't the right place or if I'm missing something obvious.

SYSTEM DETAILS
Computer: Macbook Air
Memory: 8GB
Chip: Apple M1
Sonoma 14.2.1
git version 2.39.3 (Apple Git-146)
Homebrew 4.2.16
/opt/brew/opt/pkg-config (appears installed here)
Rstudio: Version 2023.03.1+446 (2023.03.1+446)
R version 4.3.3

ERROR DETAILS

R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin23.2.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Workspace loaded from ~/.RData]

install.packages("usethis")
Installing package into ‘/opt/homebrew/lib/R/4.3/site-library’
(as ‘lib’ is unspecified)
also installing the dependency ‘gert’

trying URL 'https://cran.rstudio.com/src/contrib/gert_2.0.1.tar.gz'
Content type 'application/x-gzip' length 122723 bytes (119 KB)

downloaded 119 KB

trying URL 'https://cran.rstudio.com/src/contrib/usethis_2.2.3.tar.gz'
Content type 'application/x-gzip' length 371088 bytes (362 KB)

downloaded 362 KB

  • installing source package ‘gert’ ...
    ** package ‘gert’ successfully unpacked and MD5 sums checked
    ** using staged installation
    Homebrew 4.2.16
    Using PKG_CFLAGS=-I/opt/homebrew/opt/libgit2/include
    Using PKG_LIBS=-L/opt/homebrew/opt/libgit2/lib -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] ---------------------------
    :1:10: fatal error: 'git2.h' file not found
    #include <git2.h>
    ^~~~~~~~
    1 error generated.

ERROR: configuration failed for package ‘gert’

  • removing ‘/opt/homebrew/lib/R/4.3/site-library/gert’
    Warning in install.packages :
    installation of package ‘gert’ had non-zero exit status
    ERROR: dependency ‘gert’ is not available for package ‘usethis’
  • removing ‘/opt/homebrew/lib/R/4.3/site-library/usethis’
    Warning in install.packages :
    installation of package ‘usethis’ had non-zero exit status

The downloaded source packages are in
‘/private/var/folders/2x/ynk03js54vx7vv8wgbyyzr7h0000gn/T/RtmpTuO3yB/downloaded_packages’

@jennybc
Copy link
Member

jennybc commented Apr 2, 2024

FWIW this is a failure to install the gert package, from source. Installing usethis is what caused you to discover this, but you would presumably get the same result with a direct install.packages("gert"), i.e. this doesn't have anything to do with usethis.

I would zoom out a bit and ask some questions:

  • Why is install.packages() trying to install source packages instead of binary? You really shouldn't be trying to build gert unless you really want to, i.e. you should be installing the prebuilt macOS binary from CRAN.
  • How did you install R from homebrew? In general, I advise against homebrew R unless you have very specific reasons you want to do that. Instead I strongly advise installing R from CRAN (https://cran.r-project.org/) or with rig (https://github.com/r-lib/rig).

Here's a write-up of why we advise against homebrew for installing R:

https://github.com/rstats-wtf/what-they-forgot/blob/8205e16230ca8458c461405b43afdc0450bae584/system-prep-for-build.qmd#L69-L91

If you still want to use it for installing R, it's very important to do brew install --cask r and not brew install r.

@jennybc jennybc closed this as completed Apr 2, 2024
@markariosd3
Copy link
Author

markariosd3 commented Apr 2, 2024 via email

@loicbaron
Copy link

On a MacOS using homebrew, install libgit2: brew install libgit2
Then install.packages("usethis"). This worked fine for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants