The is for Linux.  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


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

LINUX

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

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 - linux

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

curl https://www.cns.nyu.edu/linux/matlab$ver.tgz | tar xz -C /usr/local


#: Put binaries in your path.

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

cd /usr/local/bin

ln -s /usr/local/matlab$ver/bin/matlab matlab$ver

#: matlab_jenv does not exist for 9.9 or below

ln -s /usr/local/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


# For these matlab versions

#: ver=9.11

#: ver=9.9

#: ver=9.6

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

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 /usr/local/matlab/bin/matlab

#: matlab_jenv does not exist for 9.9 or below

ln -s /usr/local/matlab/bin/matlab_jenv



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

2.  Install JDK current - do once

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

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


#: Install use apt

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

wget -O - https://apt.corretto.aws/corretto.key | sudo gpg --dearmor -o /usr/share/keyrings/corretto-keyring.gpg && \

echo "deb [signed-by=/usr/share/keyrings/corretto-keyring.gpg] https://apt.corretto.aws stable main" | sudo tee /etc/apt/sources.list.d/corretto.list


#: Install current jdk v8

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

apt-get update;   apt-get install -y java-1.8.0-amazon-corretto-jdk

cd /usr/lib/jvm ; ln -s java-1.8.0-amazon-corretto jdk


#: To remove

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

apt remove --purge java-1.8.0-amazon-corretto-jdk 

#: remove java common package

apt autoremove


cd /etc/apt/sources.list.d/

rm corretto.list*



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

3.  Set java env 

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

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


#: For 24.2, 9.13

matlab_jenv$ver -allusers /usr/lib/jvm/jdk


#: For 9.11,  9.9, 9.6

#; we linked it in

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

ln -s /usr/lib/jvm/jdk/jre



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

4.  Spot check matlab

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

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