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

419 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 4 Apr 2024 at 0:00
Edited: MathWorks Support Team on 4 Apr 2024 at 12:57
By default, Windows versions of MATLAB ship with the Oracle® version 8 Java Virtual Machine™ (JVM). However, you have the option to attempt to use other JVMs. MATLAB supports OpenJDK Java 8 for releases R2020a and later and since R2023a, MATLAB also supports OpenJDK Java 11. More details about what specific applications are supported for the most recent MATLAB release are listed on the following page:
MATLAB Interfaces to Other Languages
MATLAB is fully supported only for these specified versions of the JVM software. Some components may not work properly under a different version of the JVM software. 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.
If you choose to change the JVM software version used by MATLAB, follow the instructions below based on the release of MATLAB you are using.


R2021b and newer

Please follow the instructions from our jenv documentation page in the link below.


R2021a and older

A specific version of the JVM can be set with the environment variable "MATLAB_JAVA". To set, MATLAB_JAVA follow the instructions below.
  1. Close all instances of MATLAB
  2. Open the Windows Start Menu
  3. Search for "Environment variables"
  4. Select the result reading "Edit the system environment variables"
  5. Select the Environment Variables button
  6. In the system variables section, select "New..."
  7. Make the variable name MATLAB_JAVA and the variable value the path to your desired JRE (ex: C:\Program Files\Java\jre-1.8)
  8. Press OK when finished entering the variable information
  9. Press OK again to close the Environment Variables window
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.
To revert back to the shipped version of the JVM, remove the "MATLAB_JAVA" environment variable from the window previously used to add it.
To change the JVM MATLAB uses for other platforms, use the links below.



More Answers (0)


Find more on Startup and Shutdown in Help Center and File Exchange


No tags entered yet.

Community Treasure Hunt

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

Start Hunting!