Join GitHub today
Installing RStan on Linux
This page contains instructions for configuring your C++ toolchain on Linux in order to use RStan.
Using RStan requires either
g++ version 4.9 and up or
clang++ version 3.4 and up as they support the C++14 standard. Such a compiler is almost always available and is likely already installed system wide but may not be the default compiler on older systems such as RHEL7.
Installing from the repository
It is possible to install the a packaged RStan binary from your distributions repository.
Ubuntu users can install a binary version of RStan with
# Add marutter's c2d4u repository, (and rrutter for CRAN builds too) sudo add-apt-repository -y "ppa:marutter/rrutter" sudo add-apt-repository -y "ppa:marutter/c2d4u" sudo apt-get update sudo apt-get install r-cran-rstan
Debian users of DebianTesting can use
apt-get install r-cran-rstan
C++ toolchain configuration
The following will create or edit a configuration file for the C++ toolchain
dotR <- file.path(Sys.getenv("HOME"), ".R") if (!file.exists(dotR)) dir.create(dotR) M <- file.path(dotR, "Makevars") if (!file.exists(M)) file.create(M) cat("\nCXX14FLAGS=-O3 -march=native -mtune=native -fPIC", "CXX14=g++", # or clang++ but you may need a version postfix file = M, sep = "\n", append = TRUE)
Note that your compiler may have a version number postfix, such as
At this point, you can proceed to How to Use RStan if you have installed the binary version of it or otherwise build it from source.
Installing RStan from source
remove.packages("rstan") if (file.exists(".RData")) file.remove(".RData")
and then restart R and set the desired number of cores to use during installation
Sys.setenv(MAKEFLAGS = "-j4") # four cores used
Finally, either do
install.packages("rstan", type = "source")
to install the CRAN version of RStan from source or
remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan", build_opts = "")
to install the development version of RStan from GitHub.
- Then proceed to How to Use RStan