Main Content

jenv

R2026b

Set Java path for MATLAB

    Description

    jenv(version) sets the Java® path for MATLAB® to a Java version on your system or the version in a specified folder. For supported version information, see Versions of OpenJDK Compatible with MATLAB by Release. For more information, see Configure Your System to Use Java.

    This function sets the path for all future MATLAB sessions but does not change the path for other applications on your computer.

    jenv("-clear") removes the JRE™ configuration for an individual user. Use this option after installing the MATLAB Support for OpenJDK® add-on. (since R2026a)

    When you clear the JRE configuration, MATLAB looks for the JRE in this order:

    1. Location of the MATLAB Support for OpenJDK add-on.

    2. Depending on your operating system:

      • For Windows® and Linux®, the system-installed Java.

        Before R2026b: The version of Java shipped with MATLAB.

      • For Apple silicon, the system-installed Java.

    jenv("-allusers",___) configures the JRE for all users of a MATLAB installation. Use this syntax with any of the input argument combinations in previous syntaxes.

    je = jenv returns information about the current Java environment as a JavaEnvironment object.

    je = jenv(___) returns information about the Java environment after making the specified Java configuration changes. Use this syntax with any of the input argument combinations in previous syntaxes.

    Examples

    collapse all

    Use the version of Java installed at C:\Program Files\Java\jre1.8.0_202.

    jenv("C:\Program Files\Java\jre1.8.0_202")
    

    If the JRE has been loaded, restart MATLAB. To verify, check if the JavaEnvironment Status property is set to loaded:

    jenv
    ans = 
    
      JavaEnvironment with properties:
    
              Version: "Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode"
                 Home: "C:\Program Files\MATLAB\R2026a\sys\java\jre\win64\jre"
              Library: "C:\Program Files\MATLAB\R2026a\sys\java\jre\win64\jre\bin\server\jvm.dll"
               Status: loaded
        Configuration: "factory"

    Then, verify the version.

    version -java

    If you have administrator privileges, you can specify the Java version for all users.

    Start MATLAB with administrator privileges. Specify for all users to use the version of Java on their system.

    jenv -allusers system
    

    Restart MATLAB to use the specified version.

    Then, verify the version.

    version -java

    Input Arguments

    collapse all

    Java version, specified as a string scalar or character vector that contains one of these values:

    • "system" — The function searches your system for Java version 8. If version 8 is not found, the function searches for version 11, then for version 17. The search is based on platform.

      • Windows platforms:

        1. java -version system command

        2. Registry entries

      • Linux platforms:

        1. JAVA_HOME environment variable

        2. System path

      • macOS platforms:

        1. /usr/libexec/java_home -f -v 1.8

        2. /usr/libexec/java_home -f -v 11

        3. /usr/libexec/java_home -f -v 17

    • "factory" — Same as "system". (since R2026b)

    • Custom Java path — Specify the folder for an installed Java version on your computer.

    For version information, see Versions of OpenJDK Compatible with MATLAB by Release.

    Example: jenv("system")

    Example: jenv("/usr/local/jre") for OpenJDK JRE on Linux and macOS

    Tips

    • To use the OpenJDK JRE, you can either install the MATLAB Support for OpenJDK add-on or download a compatible OpenJDK version from https://adoptium.net.

    Version History

    Introduced in R2021b

    expand all