How do I change the Java Virtual Machine (JVM) that MATLAB is using on macOS?

How do I change the Java Virtual Machine (JVM) that MATLAB is using on macOS?

 Accepted Answer

Below are some version- and architecture-specific notes and instructions for changing the JVM that MATLAB is using. If you select an unsupported Java version, be aware that some components may not work properly. For example, calling functions in a dynamically linked library that was created with a different JVM software version than that used by MATLAB might cause a segmentation violation error message.
Notes

Default JRE

Intel MATLAB
  • R2013a and earlier: MATLAB uses the system-wide JVM
  • R2013b-R2025b: MATLAB uses the JRE bundled with MATLAB. Note that R2025b is the last release for Intel MATLAB.
Apple Silicon MATLAB
  • R2023b-R2026a: MATLAB does not ship with a JRE. You must install a supported version of OpenJDK.
  • R2026b and later: MATLAB does not ship with a JRE. You only need to install a supported version of OpenJDK if you are using Products or Features that have Java dependencies (e.g.,  Database Toolbox and Java Interface).

Supported versions of OpenJDK 

  • See Versions of OpenJDK Compatible with MATLAB by Release for details.
  • R2026a and newer: You can use the MATLAB Add-Ons manager to install a supported Open JDK version. In the Toolstrip at the top, select "Home", then "Add-Ons". In the "Add-Ons Explorer" search for "JDK". Select "MATLAB Support for Open JDK" and follow the instructions. This should configure MATLAB for the installed JRE, but you can use "jenv" or (outside MATLAB) "matlab_jenv" to check and configure the JRE, as indicated in the instructions below.
How to change the JVM used by MATLAB

R2021b and newer

Please follow the instructions: Set Java path for MATLAB (jenv). If you don't have MATLAB installed and are only using the MATLAB Runtime, follow the instructions: Set the Java path for MATLAB from system prompt (matlab_jenv).
Note: MATLAB_JAVA takes higher precedence over jenv/matlab_jenv when both are set.

R13 and newer

On the bash shell, execute:
export MATLAB_JAVA=<JRE path>
This setting will apply to MATLAB launched from that shell window.

 

On csh or tcsh shells, use the "setenv" command to set the MATLAB_JAVA environment variable. For example:
setenv MATLAB_JAVA <JRE path>
This command needs to be run in every new shell window.

 

Verifying the Installation

To verify that MATLAB is using the correct version of the JVM software, type the following at the MATLAB prompt:
>> version -java

 

If MATLAB is not using your value of MATLAB_JAVA, you may need to logout and log back in again.

 

Other Operating Systems/Platforms

To change the JVM MATLAB uses for other systems, use the following links.

1 Comment

Posted as a comment-as-flag by James McDaniel :
I have not been able to follow these instructions. Why can't this be done by the MATLAB installer?

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!