MATLAB Answers

2

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

Asked by MathWorks Support Team on 20 May 2014
Latest activity Commented on by Jeff Mandel on 13 Nov 2019 at 20:33
I would like to use a different version of JVM than the default used in MATLAB for Linux.

Tags

No tags entered yet.

2 Answers

Answer by MathWorks Support Team on 28 May 2019
Edited by MathWorks Support Team on 28 May 2019
 Accepted Answer

MATLAB ships with one specific version of the JVM software on Linux OS depending on the release. MATLAB is fully supported only on these shipped 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 MATLAB_JAVA environment variable to this path (see below).
4. Start MATLAB while that environment variable is set (see below).
Setting MATLAB to use new Java
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.
Other OS:
To change the JVM MATLAB uses for other systems, use the following links.
Windows OS:
Mac OS:

  1 Comment

This set me back an hour figuring out why mcc was producing a class file with version 55 (java 11) rather than 52 (java 8). I recently installed Java 11 on my Ubuntu 16.04 machine. In the process, it created a profile:
ls /etc/profile.d/jdk.*
/etc/profile.d/jdk.csh /etc/profile.d/jdk.sh
In each of these files are commands to set the JAVA_HOME and PATH environment variables:
more /etc/profile.d/jdk.sh
export J2SDKDIR=/usr/lib/jvm/java-11-oracle
export J2REDIR=/usr/lib/jvm/java-11-oracle
export PATH=$PATH:/usr/lib/jvm/java-11-oracle/bin:/usr/lib/jvm/java-11-oracle/db/bin
export JAVA_HOME=/usr/lib/jvm/java-11-oracle
The clue is:
> version -java
ans = 'Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode'
> getenv JAVA_HOME
ans = '/usr/lib/jvm/java-11-oracle'
Changing the MATLAB_JAVA environment variable has no effect on this. Setting JAVA_HOME from the command line before invoking matlab didn't either. Only editting the /etc/profile.d/jdk.sh file, then logging out and in fixed it.
Note that outside of matlab, everything was happy:
javac -version
javac 1.8.0_201
echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
Hope this helps someone

Sign in to comment.


Answer by Manuel Alejandro Ceron on 24 May 2017

what can i do if i get this: zsh: parse error near `\n'

  0 Comments

Sign in to comment.