Matlab does not find Java Runtime Environment (Mac Silicon)

Hello, I'm trying to install matlab in my computer (Macbook pro, M2). It requires a java runtime environment (JRE). It give as an option the one from Amazon, but I have a JRE installed directly from Java's website. After reading this article on how to change the JRE path from the command window, I run the following, from the hardrive location:
<path/to/matlab_jenv> <path/to/JRE>
I'm copy-pasting the JRE path from the java applet. Anyway, the error I'm getting is this:
"Unable to validate Java path: <path/to/JRE>".
Can anyone help? Thank you!!

8 Kommentare

Update: I figured out the problem. A bit of a facepalm but here it is in case it's useful for others in the future:
For the path to JRE, I had:
/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk
But I'm supposed to go a bit further:
/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
To figure out the exact path to your JRE, type in your terminal:
/usr/libexec/java_home -V
I followed the instructions from this question.
Notice though, that as of now Corretto 11 also works.
Hello
I have the same problem to configure the path of the JRE
In which matlab file (2023b) do you change the path
Thanks a lot for your answer!
Sorry , it is on a macbook pro M1
Efren
Efren am 1 Mai 2024
Bearbeitet: Efren am 1 Mai 2024
No need to change the file manually. If you inspect the contents of your matlab installation using Finder, you will see there is an executable file called matlab_jenv. Basically you need to run this executable in your terminal and indicate the path to the JRE. I'll try to go step by step.
In my case matlab_jenv was in: Applications/Matlab_XXX/bin/maca64, where Matlab_XXX will refer to your specific Matlab version.
Since the folders may change slightly for you, you can search in Finder for matlab_jenv. Once you do that, take note of the full path to get there. Let's call it path A.
Navigation notes:
  • This "Applications" folder is the one at the hardrive level, not the user level. In Finder click "go", select "computer", select the hardrive, and then you should find this folder.
  • When you get to Matlab_XXX it may show as an application and not as a folder. Two-finger click (right click) on it and select "show package content", now you will see the folder associated to it.
Now you need to find the path to your JRE. If you installed Amazon Corretto, it should be in something similar to /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home, but it may change. To figure out exactly what this path is, open your terminal and run
/usr/libexec/java_home -V
Take note of this path. Let's call it path B.
To recap, your matlab installation is likely in the Applications folder (the one at the hardrive level, not the user level), and your coretto installation is likely in the Libraries folder (also at the hardrive level). Your task is:
  1. Find the folder in Matlab containing the executable file matlab_jenv.
  2. Find where your JRE is.
  3. Use matlab_jenv to set the path to your JRE.
To do part 3, open your terminal. Now write path A, and make sure it starts with a '/' to indicate this path starts at the hardrive level and not the user level. add matlab_jenv to it. Press space. Now write path B, making sure it also starts with a '/'. At the end it should look like this:
/PathA/matlab_jenv /PathB
I hope this works!
The answer did not work with the Oracle install of Java (1.8.0_411). However, after installing Amazon Corretto 11, following the instructions resulted in success.
Yes this is not working for my case too. I am getting
"Java version at "/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home" not supported"
Chris
Chris am 19 Aug. 2024
Bearbeitet: Chris am 19 Aug. 2024
@Aditya, according to this page, Java/Corretto is currently only supported up to version 17.
1,直接从java官网下载安装的jre,是没有办法支持matlab运行的。比如,最开始是找不到java的运行环境,按照贴主的提示操作后,不再提示运行环境错误,而变成了打开软件闪退(错误报告: MATLAB 在处理 Java 虚拟机(JVM)相关的任务时发生了错误。)
2,安装好Amazon Corretto 11后(https://ww2.mathworks.cn/support/requirements/apple-silicon.html),在终端执行:/Applications/MATLAB_R2024a.app/bin/maca64/matlab_jenv /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home。
能够正常运行了

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Marius
Marius am 28 Sep. 2024
Bearbeitet: Marius am 28 Sep. 2024
Hi,
I was having the same issue. I am using a Mac M3Pro which is also on the Apple Silicone.
First, get the location of your JAVA 11 runtime. I have multiple JDKs installed and managed the installation with SDKMAN.
Little installation guide for SDKMAN:
curl -s "https://get.sdkman.io" | bash
source "/Users/username/.sdkman/bin/sdkman-init.sh"
NB: SDKMAN additions are made to your .zshrc after installation. For SDKMAN to work THESE ADDITIONS NEED TO BE KEPT AT THE BOTTOM OF YOUR .ZSHRC!!
Once you found your desired java versions by running:
sdk list java
Run this to install your desired jdk:
sdk install java 11.0.23-amzn
You'll need to export it to your ~/.zshrc. Open up your ~/.zshrc with sudo nano ~/.zshrc and add this:
export MATLAB_JAVA=/Users/username/.sdkman/candidates/java/11.0.23-amzn
Update ~/.zshrc by running:
source ~/.zshrc
You can now run this command in your terminal to launch MATLAB by pointing it to your desired JDK (edit 20xx to match your MATLAB version. Mine was 2024b):
MATLAB_JAVA=$MATLAB_JAVA /Applications/MATLAB_R20xx.app/bin/matlab

4 Kommentare

Thank you so much! This worked. The only downside is that you always have to open MATLAB using your last command in the terminal. You can create an automation to make the process simple.
Nice one, glad to hear!
Yeah agreed, I created a shell script runMatlab.sh with this command inside.
You can follow this to make it work:
  1. open a terminal in your user directory
  2. mkdir matlabShortcut
  3. cd matlabShortcut
  4. touch runMatlab.sh
  5. nano runMatlab.sh
  6. insert this inside the file:
#!/bin/bash
MATLAB_JAVA=$MATLAB_JAVA /Applications/MATLAB_R2024b.app/bin/matlab
7. press Control+X, then press Y and Enter
8. in the terminal in the same location as your file run:
chmod +x runMatlab.sh
9. run ./runMatlab.sh
I just found a way to make MATLAB open every single time from the app icon, without any type of script.
First you need to get access to MATLAB's Command Window, and from there, you can change the path to the JRE permanently using the following command:
>> jenv('/Users/username/.sdkman/candidates/java/11.0.23-amzn')
From now on, everytime you open the app, it will use the JRE found on the path you specified in the command above.
You are the GOAT

Melden Sie sich an, um zu kommentieren.

Travis Massey
Travis Massey am 25 Apr. 2024
Bearbeitet: Walter Roberson am 25 Apr. 2024

0 Stimmen

I ran into this same issue in Windows today. The problem was that I had downloaded 32-bit Java (the default) instead of 64-bit.
I recognized that Java for Mac/ARM should only be 64-bit, but perhaps your default download also grabbed the wrong version, and there's another more appropriate version.

3 Kommentare

Thanks, unfortunately that was not the issue. I uninstalled and tried again and double checked I have the correct versions of everything. I've tried both with the JRE from java.com and the JDK from Amazon (the one recommended by Matlab): Corretto. I've tried both versions 8 and 11 of Corretto. Still no luck. I still get the "unable to validate Java path" error.
I have the same problem. I tried the solution from Efren but it still just pops-in and pops-out and vanish. It's not stable to run the program. Any other solutions?
Efren
Efren am 15 Mai 2024
Bearbeitet: Efren am 15 Mai 2024
Did you check my comment above, in the original question? I give a step by step of te solution I found. (see my comment in response to Plante jean-luc's comment).

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 24 Apr. 2024

Kommentiert:

am 11 Okt. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by