As of version 4.0 (April 2020) R for Windows uses a brand new toolchain bundle called Rtools40.
This version of Rtools upgrades the mingw-w64 gcc toolchains to 8.3.0, and also introduces a new build system based on msys2, which makes easier to build and maintain R itself as well as system libraries needed by R packages on Windows. For more information about this, see the links in the bottom of this document.
Older versions of Rtools: This document talks about Rtools40, the current version used for R-4.0 and up. For previous versions of Rtools (used up till R 3.6), please see this page.
Note that you only need rtools40 if you want to build R packages which contain C/C++/Fortran code. By default, R for Windows installs the precompiled "binary packages" from CRAN, for which you do not need rtools!
To use rtools40, download the installer from CRAN:
- On Windows 64-bit: rtools40-x86_64.exe (recommended: includes both i386 and x64 compilers)
- On Windows 32-bit: rtools40-i686.exe (i386 compilers only)
After the installation is completed, you need to perform one more step to be able to compile R packages: you need to put the location of the rtools make utilities (bash
, make
, etc) on the PATH
. The easiest way to do so is create a text file .Renviron
in your Documents folder which contains the following line:
PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"
You can do this with a text editor, or you can even do it from R like so:
# Automatically put Rtools on the PATH
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")
Now restart R and verify that make
can be found, which should show the path to your rtools installation. If this works you can try to install an R package from source:
# Confirm that make.exe is on the PATH
Sys.which("make")
## "C:\\rtools40\\usr\\bin\\make.exe"
# Try to install a package
install.packages("jsonlite", type = "source")
If this succeeds, you're good! See the links below to learn more about rtools40 and the Windows build infrastructure.
Documentation about rtools40 for R users and package authors:
- rtools40: some info about the new rtools build system
- faq: common issues with Rtools40 and R on Windows.
Other resources with information about building R and system libraries:
- r-base: Scripts for building R for Windows using Rtools40.
- rtools-packages: Toolchains and static libraries for Rtools 4.0 (GCC 8+)
- rtools-backports: Backported C/C++ libraries for the gcc-4.9.3 legacy toolchain (for R 3.3 - 3.6)
- rtools-installer: Builds the Rtools40 installer bundle.