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

113 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Nov 2023 at 0:00
Edited: MathWorks Support Team on 21 Nov 2023 at 20:59
By default, MATLAB ships with the Oracle® version 8 JVM™. However, you can change it to use an OpenJDK JVM. MATLAB supports OpenJDK Java 8 for releases R2020a and later. 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 is fully supported only for these specified versions of the JVM software. Some components might 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, you must:
1.  Download and install the desired version of the JRE (Java Runtime Environment) or the JDK (Java Development Kit).  The latter contains the JRE and development tools.
2.  Determine the path of the JRE directory within that installation.  This varies by platform and whether you downloaded the JRE or JDK (see below).
3.  Set the path to the JRE directory.
Setting MATLAB to use new Java
For MATLAB R2021b and later versions
Use MATLAB's jenv or matlab_jenv command. For example:
For MATLAB R2021a and earlier versions
The JDK or JRE will be located in the directory where you installed it after downloading.  The JRE path is the directory named "jre" beneath that directory.
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.
On the bash shell, execute:
export MATLAB_JAVA=<JRE path>
This setting will apply to MATLAB launched from that 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.

More Answers (0)


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


Community Treasure Hunt

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

Start Hunting!