This guide will walk you through downloading, installing,
and managing Java environments for your R projects using the
rJavaEnv
package. We’ll cover setting up the environment,
unsetting it, managing distributions, installing Java, and checking Java
versions.
Install rJavaEnv
: First, install
the development version of rJavaEnv
from GitHub:
Quick Install Java: To quickly install Java 21 (default) in your current project directory and set the environment:
This command:
Expected output:
Platform detected or provided: <your_platform>
Architecture detected or provided: <your_architecture>
Downloading Java 21 (Corretto) for <your_platform> <your_architecture> to <destination_path>
Download completed.
Java 21 (Corretto) for <your_platform> <your_architecture> installed at <installed_path> and symlinked to <symlink_path>
Step-by-Step Installation: If you prefer a more controlled process:
Download Java:
This will download Java 21 from the Corretto distribution.
Expected output:
Downloading Java 21 (Corretto) for <your_platform> <your_architecture> to <destination_path>
Download completed.
Install Java:
This will install the downloaded Java distribution and set the JAVA_HOME and PATH environment variables.
Expected output:
Java 21 (Corretto) installed at <installed_path> and symlinked to <symlink_path>
Set the JAVA_HOME and PATH environment variables to the installed Java directory:
This function sets the JAVA_HOME and PATH environment variables for
the current R session and/or the project .Rprofile
file.
Expected output:
Current R Session: JAVA_HOME and PATH set to <java_home_path>
Current R Project/Working Directory: JAVA_HOME and PATH set to <java_home_path> in .Rprofile in <project_directory>
Remove the JAVA_HOME and PATH environment variables settings from the
project .Rprofile
file:
This function removes the JAVA_HOME and PATH environment variables
from the .Rprofile
file in the project directory.
Expected output:
Removed JAVA_HOME settings from .Rprofile in <project_directory>
List Cached Java Distributions:
This function lists all Java distributions cached in the user-specific data directory.
Expected output:
<data.frame or vector of cached Java distributions>
Clear Cached Java Distributions:
This function clears all cached Java distributions.
Expected output:
Java distributions cache cleared.
List Installed Java Versions:
This function lists all installed Java versions in the user-specific data directory.
Expected output:
<data.frame or vector of installed Java versions>
Clear Installed Java Versions:
This function clears all installed Java versions.
Expected output:
Java installations cache cleared.
List Project-Specific Java Versions:
This function lists all Java versions symlinked in the current project directory.
Expected output:
<data.frame or vector of project-specific Java versions>
Clear Project-Specific Java Versions:
This function clears all Java versions symlinked in the current project directory.
Expected output:
All Java symlinks in the project have been cleared.
Check Installed Java Version using Terminal Commands:
This function checks the Java version using terminal commands and prints the Java version and path.
Expected output:
JAVA_HOME: <current_java_home>
Java path: <java_path>
Java version:
<java_version_details>
Check Java Version using rJava
in a Separate
R Session:
This function checks the Java version using rJava
in a
separate R session.
Expected output:
With the current session's JAVA_HOME <java_version_details>
or
With the user-specified JAVA_HOME <java_version_details>