Check installed Java version using terminal commands
Arguments
- java_home
Path to Java home directory. If NULL, the function uses the JAVA_HOME environment variable.
- quiet
A
logicalvalue indicating whether to suppress messages. Can beTRUEorFALSE.- .use_cache
Logical. If
TRUE, uses cached results for repeated calls with the same JAVA_HOME. IfFALSE(default), forces a fresh check. Set toTRUEfor performance in loops or repeated checks within the same session.
Value
A character vector of length 1 containing the major Java version, or FALSE if JAVA_HOME is not set or the Java executable cannot be found.
Performance
This function is memoised (cached) within the R session using the effective
JAVA_HOME as cache key. First call for a given JAVA_HOME: ~37ms. Subsequent
calls (with .use_cache = TRUE): <1ms. When you switch Java versions via use_java(), JAVA_HOME
changes, creating a new cache entry. Cache is session-scoped.
Examples
# \donttest{
java_check_version_cmd()
#> JAVA_HOME:
#> /home/runner/.cache/R/rJavaEnv/installed/linux/x64/Corretto/native/17
#> Java path:
#> /home/runner/.cache/R/rJavaEnv/installed/linux/x64/Corretto/native/17/bin/java
#> Java version: "openjdk version \"17.0.17\" 2025-10-21 LTS OpenJDK Runtime
#> Environment Corretto-17.0.17.10.1 (build 17.0.17+10-LTS) OpenJDK 64-Bit Server
#> VM Corretto-17.0.17.10.1 (build 17.0.17+10-LTS, mixed mode, sharing)"
#> [1] "17"
# }
