In order to compile R for macOS, you will need the following tools:
- Xcode developer tools from Apple
Xcode can be obtained from Apple AppStore and the Xcode developer page. Older versions are available in the "more" section of the Developer pages (Apple developer account necessary). On modern macOS versions you can simply use
sudo xcode-select --install
which installs Xcode command line tools which are sufficient to build R (however, if you want to also build the R.app GUI you do need the full Xcode installation).
- GNU Fortran compiler
R and some contributed package require a FORTRAN compiler.
Unfortunately Xcode doesn't contain a Fortran compiler, therefore you will have to install one.
Depending on the type of your Mac (old Intel Macs vs new arm64-based Apple silicon Macs) we recommend the following options:
We recommend the official GNU Fortran binaries from F.X.Coudert. CRAN High-Sierra builds currently use GNU Gortran 8.2 from that page (note that even though compiled for Mojave it is compatible with High Sierra).
Intel Macs: gfortran-8.2-Mojave.dmg
(ca. 87MB, GNU Fortran 8.2 from F.X.Coudert)SHA256 hash: 81d379231ba5671a5ef1b7832531f53be5a1c651701a61d87e1d877c4f06d369
This is a copy of GNU Fortran 8.2 build from https://github.com/fxcoudert/gfortran-for-macOS/releases
Make sure you add /usr/local/gfortran/bin to your PATH in order to use this compiler. This can be done, e.g. by
Apple silicon Macs
For arm64-based Macs (M1 and above) we use experimental branch of GNU Fortran:
This binary unpacks into /opt/R/arm64/gfortran plus a symbolic link in /opt/R/arm64/bin/gfortran. To unpack use
tar fxz gfortran-12.0.1-20220312-is-darwin20-arm64.tar.xz -C /
(prefix with sudo if you need admin permissions to write to /opt/R/arm64). To use set
In addition, /opt/R/arm64/gfortran/SDK has to point to your macOS SDK. The binary above points to MacOSX11.sdk of Xcode Command Line Tools, but you may need to change it to match your installation. We include a script gfortran-update-sdk in the above tar ball that you can simply run (prefix with sudo if you require admin permissions).
For completeness, previous version (before R 4.2.0):
In order to retain compatibility with native R we recommend using above tools. Although it is possible to compile R using tools from other package managers such as Homebrew, MacPorts or Fink, such binaries are by definition incompatible with macOS native libraries and applications. If you choose one of those package managers, make sure you compile everything
using those tools including R and all packages and libraries you intend to use.
Additional information on the OpenMP page is available for those interested in OpenMP support which is not supported by Apple, but still possible with additonal libraries.
Old versions of R provided fall-back versions of dependend libraries. This is no longer the case, the following libraries are not present in most recent macOS (or are too old) and have to be installed before R can be compiled:
Binaries for the above libraries are available from the /bin
directory for the builds we use. Those are binaries used by CRAN
and are built using the recipes system
, thus can be transparently re-built accordingly. If you wish to compile all dependencies yourself use the following commands:
git clone https://github.com/R-macos/recipes.git
This will build and install all dependencies necessary to compile R including optional capabilities such as cairo, tiff, jpeg, png and texinfo. On Intel Macs the default prefix is /usr/local (another recommended alternative is /opt/R/x86_64) and on arm64 Macs it is /opt/R/arm64. It may be convenient to setup the target to be managed by the current user, e.g.:
sudo mkdir -p /opt/R/arm64
sudo chown $USER /opt/R/arm64
after which sudo is no longer required. For more details, please see the documentation of the recipes build system.
Optional tools and libraries
The following tools and libraries are optional. R can be compiled without them, but they provide additional capabilities to R.
In order to produce documentation, LaTeX is necessary. It can be obtained from several places, for example as a part of MacTeX.
- GNU readline
Although macOS comes with readline-replacement library (libedit), it lacks some functionality like backward search etc. Therefore many user prefer GNU readline.
If you want to check out R from the SVN repository, you will need subversion. It was included in Xcode 9 and earlier, but is no longer. We are providing a signed binary:
subversion-1.14.0-darwin15.6.tar.gz (SHA1: 9dab09d6cf608bea6224bdc3ec3e95893e4e9800)
which works on OS X 10.11 (El Capitan) and higher, is relocatable, i.e., you can put it anywhere you want since it only depends on system libraries.
Similarly, the arm64 version is also available: subversion-1.14.1-darwin.20-arm64.tar.gz (SHA1: 2e6068749ded28d5080a7cb37ddee5fdda16858a)
(Static build with: apr-1.7.0, apr-util-1.6.1, openssl-1.1.1g, serf-1.3.9, sqlite-3.33.0, subversion-1.14.0)
This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org/)
(sources for open source software not linked directly)
Old version of this page for much older OS X versions.
All software is provided "as is" and any express or implied warranties, including, but but not limited to the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the publisher, copyright owner or contributors be liable for any direct, indirect, incidental,special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.