Some R packages (e.g., sglasso,
RcppArmadillo) include source code written in C++ or
Fortran. To compile these packages from source, your system must have a
working Fortran compiler, specifically
gfortran.
This guide covers installation instructions for both Windows and macOS on one page.
Rtools includes gfortran and other compilers needed for
building R packages.
Download Rtools from:
https://cran.r-project.org/bin/windows/Rtools/
Install the latest version (e.g., Rtools 4.3 or above).
After installation, restart your computer and run this in R:
Sys.which("gfortran")
system("gfortran --version")
You should see version output like:
GNU Fortran (GCC) 13.2.0
If
gfortranis not found, ensure Rtools is added to your PATH. You can add this line to.Renviron:
PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"
Open Terminal and run:
xcode-select --install
This installs essential development tools including
clang.
Go to:
👉 https://mac.r-project.org/tools/
Download and install:
For Apple Silicon (M1/M2/M3):
gfortran-13.2-arm64.pkg (or latest ARM version)
For Intel Macs:
gfortran-13.2.pkg or gfortran-12.pkg
(Intel-compatible version)
Check from Terminal:
gfortran --version
You should see:
GNU Fortran (GCC) 13.2.0
If the command is not found, restart your Terminal or reinstall from
the correct .pkg.
Once gfortran is properly installed, try compiling a
package from source:
install.packages("devtools")
devtools::install_github("byuzbasi/sglasso")
Common error messages if gfortran is not installed or
misconfigured:
non-zero exit statusundefined symbols for architecture arm64gfortran not foundFix: Ensure you have the correct gfortran version
for your CPU architecture (Intel vs ARM).
Installing the correct version of gfortran ensures
smooth compilation of many powerful R packages. If you run into errors,
double-check:
gfortran is in your system PATHRcpp are up to dateHappy coding! 🎯