The is for macOS ARM. The other platforms are similar.
The instructions below are long due to the fact each matlab version is a little different.
There are also complications if both matlab 24.2 and an earlier version are needed by the users
as 24.2 has a native ARM version and earlier versions are all Intel based.
INTRODUCTION
Here we provide a little context for the work below.
=================================
current java v8 is 1.8.0.462, 1.8.0.472
=================================
The nyu security issue with matlab is entirely due to java.
Fortunately this is fairly easy to address. Changing the java version
should not be a big deal for matlab especially if you stay within the same
major version of java. Moreover it is also easy to reverse should it be problematic.
Note that java will need to be updated every couple of months. One really need to
decouple java from matlab
****************************************
MATLAB AND JAVA
****************************************
Almost all java that comes with matlab are vulnerable/insecure
as they are somewhat outdated. Mathworks tend to keep using
the same version over several years. On the plus side, mathworks
does support the use of other jdk.
The current java v8 is 1.8.0.462. This is *not* vulnerable. Using this instead of the default version
is very unlikely to cause problems for matlab. The recent matlab comes with java version 1.8.0.202.
==========================
CURRENT AWS CORRETTO v8
==========================
version 1.8.0.442, 1.8.0.452, 1.8.0.462, 1.8.0.472
This version is suitable for machines with multiple matlabs as it has
a wider range of support from mathworks. Also for 9.13 (22.2) or below
you will need v8. Moreover for 9.13 or below, you will need the
intel version of this java.
/Library/Java/JavaVirtualMachines
/Library/Java/JavaVirtualMachines/intel
MATLAB and JDK
The notes below are mostly for 24.2, 9.13, 9.11, 9.9.
============================================================
MACOS - ARM
============================================================
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. Install matlab 24.2, 9.13, 9.11, 9.9
************************************
We install matlab24.2 if at all possible and then matlab9.13, matlab9.11,
matlab9.9 if necessary.
#: set ver and def that you wish to install
#: ==========================================
ver=24.2
#: ver=9.13
#: ver=9.11
#: ver=9.9
#: the default version [optional]
def=24.2
#: Install matlab - mac arm
#: ==========================
#: arm version - ver=24.2
curl https://www.cns.nyu.edu/mac/matlab$ver-arm.tgz | tar xz -C /Applications
#: intel version - for 9.13 or below [only has intel version]
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
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.
#: not needed for arm 24.2 - does not come with any java.
#: ver=9.13
cd /usr/local/matlab$ver/sys/java
tar czf jre.tgz jre
rm -rf jre
#: ver=9.11
#: ver=9.9
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
ln -s ../matlab/bin/matlab_jenv
mac arm
************************************
2. Install JDK current - do once
************************************
We only need to do this *once* for all the matlab versions.
If you need matlab 9.13 or below, you will need to install the
**intel** version of this jdk.
For NYU security, you will want to remove the old ones.
rm -rf /Library/Java/JavaVirtualMachines/*
#: Install current jdk v8 ARM version
#: =======================================
#: ARM version
curl -L https://corretto.aws/downloads/latest/amazon-corretto-8-aarch64-macos-jdk.tar.gz | tar xz -C /Library/Java/JavaVirtualMachines
cd /Library/Java/JavaVirtualMachines
ln -s amazon-corretto-8.jdk jdk
#: Install current jdk v8 Intel version
#: Do this for 9.13 or below
#: =======================================
#: Intel version
mkdir /Library/Java/JavaVirtualMachines/intel
curl -L https://corretto.aws/downloads/latest/amazon-corretto-8-x64-macos-jdk.tar.gz | tar xz -C /Library/Java/JavaVirtualMachines/intel
cd /Library/Java/JavaVirtualMachines/intel
ln -s amazon-corretto-8.jdk jdk
************************************
3. Set java env
************************************
This sets the java version for all users on the machine.
#: for 24.2
matlab_jenv$ver -allusers /Library/Java/JavaVirtualMachines/jdk/Contents/Home
#: for 9.13
matlab_jenv$ver -allusers /Library/Java/JavaVirtualMachines/intel/jdk/Contents/Home
#: for 9.11, 9.9
#: we linked it in
cd /usr/local/matlab$ver/sys/java/jre/maci64
ln -s /Library/Java/JavaVirtualMachines/intel/jdk/Contents/Home/jre
************************************
4. Spot check matlab
************************************
matlab$ver -nodesktop -r "version -java"
