Main Content

matlab_jenv

Set the Java path for MATLAB from system prompt

Since R2021b

To configure the JRE™, choose either the matlab_jenv version syntax for a single user account or the matlab_jenv -allusers version syntax for the MATLAB® installation.

Description

matlab_jenv version sets the Java® path to use the version included with MATLAB, a version on your system, or the version in a specified folder. For supported version information, see MATLAB Interfaces to Other Languages. For more information, see Configure Your System to Use Java.

The matlab_jenv command does not start MATLAB. To use MATLAB, start MATLAB at the same system prompt where you set the path variable.

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

example

matlab_jenv -allusers version sets the path for all users. Use to set the Java path for MATLAB Runtime.

The matlab_jenv version syntax takes precedence over the matlab_jenv -allusers version syntax.

matlab_jenv -help displays the syntax.

Examples

expand all

Use the version of Java included with MATLAB.

matlab_jenv factory

Start MATLAB to use the specified version.

Then, verify the version.

version -java

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

matlab_jenv "C:\Program Files\Java\jre1.8.0_202"

Start MATLAB to use the updated path.

Then, verify the version.

version -java

After installing MATLAB, a system administrator can set the Java path for all users.

Use the system value for the installed MATLAB. With administrative privileges, at the operating system prompt, type:

matlab_jenv -allusers system

Verify the version. Start MATLAB and type:

version -java

Input Arguments

expand all

Java version, specified as a string or a character vector with one of these values:

  • "factory" — Version included with MATLAB

  • "system" — Searches your system for a supported version 8. If not found, it 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

  • Custom Java path — Folder to an installed Java on your computer

For information about Java versions compatible with MATLAB, see MATLAB Interfaces to Other Languages.

Example: matlab_jenv system

Tips

Version History

Introduced in R2021b

expand all