cmdstan
Install CmdStan, the command-line interface to Stan — a state-of-the-art platform for Bayesian probabilistic programming and statistical inference.
The feature downloads the official CmdStan release tarball, pre-compiles the Stan C++ toolchain during the image build, and configures the CMDSTAN environment variable system-wide so that the installation survives container rebuilds without requiring any per-session setup.
Example Usage
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/MiguelRodo/DevContainerFeatures/cmdstan:1": {}
}
}With a specific version and R integration disabled:
{
"features": {
"ghcr.io/MiguelRodo/DevContainerFeatures/cmdstan:1": {
"version": "2.36.0",
"installRPackage": false
}
}
}With Python integration disabled:
{
"features": {
"ghcr.io/MiguelRodo/DevContainerFeatures/cmdstan:1": {
"installPythonPackage": false
}
}
}Options
| Option | Type | Default | Description |
|---|---|---|---|
version |
string | "latest" |
CmdStan version to install (e.g. "2.36.0"). Use "latest" to always pull the newest release. |
installDir |
string | "/opt/cmdstan" |
Base directory under which the versioned CmdStan folder is created (e.g. /opt/cmdstan/cmdstan-2.36.0). |
installRPackage |
boolean | true |
When true and R is present in the image, install the cmdstanr R package and configure it to use the system CmdStan installation. |
installPythonPackage |
boolean | true |
When true and Python/pip is present in the image, install the cmdstanpy Python package and configure it to use the system CmdStan installation. |
Notes
How the installation survives image builds
Standard Stan/R workflows (e.g. cmdstanr::install_cmdstan()) download CmdStan into the user’s home directory (~/.cmdstan/), which is often not included in the container image or is overwritten on rebuild. This feature instead:
- Installs CmdStan to
<installDir>/cmdstan-<version>/— a system-wide, persistent location. - Creates a stable symlink at
<installDir>/currentfor tooling that needs a version-independent path. - Exports
CMDSTANand updatesPATHvia/etc/profile.d/cmdstan.shand/etc/environment, so every shell session automatically sees the correct path. - If R is available, writes
CMDSTAN=<path>to R’sRenviron.siteso thatcmdstanrpicks up the system installation without any runtime configuration.
Compilation time
make build compiles the Stan Math library and several C++ utilities. Expect this step to take 3–10 minutes depending on the number of CPU cores available during the build.
Using CmdStan with R (cmdstanr)
When installRPackage is true and R is present, the feature installs cmdstanr from the Stan universe and persists the path via Renviron.site. No additional R-side configuration is needed:
library(cmdstanr)
cmdstan_path() # returns /opt/cmdstan/cmdstan-<version>Using CmdStan with Python (cmdstanpy)
When installPythonPackage is true and Python/pip is present, the feature installs cmdstanpy via pip. Because the CMDSTAN environment variable is set system-wide, cmdstanpy automatically picks up the system installation:
import cmdstanpy
cmdstanpy.cmdstan_path() # returns /opt/cmdstan/cmdstan-<version>Using CmdStan directly
After the container starts, the stanc compiler and stansummary utility are on PATH:
stanc --version
stansummary --help