Skip to contents

A reference of recurrent instructions specific for macOS.

R + Java

Depends a bit on how you’ve installed java (package manager vs. direct download)

1. Terminal

# Homebrew
brew info openjdk  
ls /opt/homebrew/opt/openjdk # expected installation location
brew --prefix openjdk # prints actual installation path (should be /opt/homebrew/opt/openjdk)
brew list | grep openjdk  

# Look for installs on computer
/usr/libexec/java_home -V  # list all java installs on computer


# R CMD javareconf # R reconfiguration

export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home # output either from /usr/libexec/java_home -V or brew --prefix openjdk
sudo R CMD javareconf # R reconfiguration with admin privileges

2. R

# Then restart R session!
install.packages("rJava") # should work now

R + gettext

Might get an error linked to gettext when trying to install a package in R

1. Terminal

# Install gettext with homebrew
brew install gettext 

# Update Makeovers
cd ~/.R
ls 
nano Makevars # or whatever text editor

In Makevars, add the following lines:

LDFLAGS += -L/opt/homebrew/opt/gettext/lib
CPPFLAGS += -I/opt/homebrew/opt/gettext/include

Save the update and close the text editor

2. R

# restart R and retry the installation
install.packages("iCantRememberTheNameOfThePackageIhadThisIssueWith")