The is for macOS Intel.  The other platforms are similar.

The instructions below are long due to the fact each matlab version is a little different.


For context, see the Introduction section of the article  How to secure Java in Matlab - macOS ARM.


MATLAB and JDK

The notes below are mostly for 24.2, 9.13, 9.11, 9.9, 9.6


============================================================

MACOS - Intel

============================================================

The instructions are meant to be done within a shell with root privileges.   We assume to start you have

done    sudo su - root    to acquire a root shell.  There are 4 basic steps.  


************************************

1.  matlab 24.2, 9.13, 9.11, 9.9, 9.6

************************************

We install matlab24.2  if at all possible and then  matlab9.13,  matlab9.11,

matlab9.9,  matlab9.6  if necessary.


#: set  ver and def

#: ==================

ver=24.2

#: ver=9.13

#: ver=9.11

#: ver=9.9

#: ver=9.6


#: the default version  [optional]

def=24.2  



#: Install matlab - mac intel

#: ==========================

#: intel version - only ver=24.2 and up

curl https://www.cns.nyu.edu/mac/matlab$ver-intel.tgz | tar xz -C /Applications


#: intel version - for 9.13 or below

curl https://www.cns.nyu.edu/mac/matlab$ver.tgz | tar xz -C /Applications


#: Put binaries in your path.

#: The symlinks use the fact /usr/local/bin  is in user path.

ln -s /Applications/MATLAB$ver.app /usr/local/matlab$ver


mkdir /usr/local/bin

cd /usr/local/bin

ln -s ../matlab$ver/bin/matlab matlab$ver

#: matlab_jenv does not exist for 9.9 or below

ln -s ../matlab$ver/bin/matlab_jenv matlab_jenv$ver



#: Remove vulnerable java

#: ======================

#: tar up the java that comes with matlab because it is vulnerable.

#: ver=24.2         

#: ver=9.13 

cd /usr/local/matlab$ver/sys/java

tar czf jre.tgz jre

rm -rf jre


#: ver=9.11

#: ver=9.9

#: ver=9.6

cd /usr/local/matlab$ver/sys/java/jre/maci64

tar czf jre.tgz jre                   

rm -rf jre



#: Do this once  [optional]

#: ===============

#: set the default matlab binaries 

cd /usr/local

ln -s matlab$def matlab

cd /usr/local/bin

ln -s ../matlab/bin/matlab

#: matlab_jenv does not exist for 9.9 or below

ln -s ../matlab/bin/matlab_jenv


ln -s /usr/libexec/java_home 



mac intel

************************************

2.  Install JDK current - do once

************************************

We only need to do this *once* for all the matlab versions.


For NYU security, you will want to remove the old ones.   

    rm -rf /Library/Java/JavaVirtualMachines/*


#: Install current jdk v8

#: =======================

curl -L https://corretto.aws/downloads/latest/amazon-corretto-8-x64-macos-jdk.tar.gz | tar xz -C /Library/Java/JavaVirtualMachines


cd /Library/Java/JavaVirtualMachines

ln -s amazon-corretto-8.jdk jdk



mac intel

************************************

3.  Set java env 

************************************

This sets the java version for all users on the machine.


#: for 24.2, 9.13

matlab_jenv$ver -allusers /Library/Java/JavaVirtualMachines/jdk/Contents/Home


#: for 9.11, 9.9, 9.6

#; we linked it in

cd /usr/local/matlab$ver/sys/java/jre/maci64

ln -s /Library/Java/JavaVirtualMachines/jdk/Contents/Home/jre



************************************

4.  Spot check matlab

************************************

matlab$ver -nodesktop -r  "version -java"