正しいのかどうかは分からんけども。
現状の記録として。
その都度、適切なものに更新する。
❯ brew list | grep jdk
openjdk
openjdk@11
❯ ls -l /usr/local/Cellar/ | grep jdk
drwxr-xr-x 3 mao admin 96 Nov 11 03:40 openjdk
drwxr-xr-x 3 mao admin 96 Jan 24 06:43 openjdk@11
❯ ls -al /usr/local/opt/ | grep jdk
lrwxr-xr-x 1 mao admin 24 Nov 11 03:40 java -> ../Cellar/openjdk/19.0.1
lrwxr-xr-x 1 mao admin 28 Jan 24 06:43 java11 -> ../Cellar/openjdk@11/11.0.18
lrwxr-xr-x 1 mao admin 24 Nov 11 03:40 openjdk -> ../Cellar/openjdk/19.0.1
lrwxr-xr-x 1 mao admin 28 Jan 24 06:43 openjdk@11 -> ../Cellar/openjdk@11/11.0.18
lrwxr-xr-x 1 mao admin 24 Nov 11 03:40 openjdk@19 -> ../Cellar/openjdk/19.0.1
ls -al /usr/local/Cellar/
❯ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
19.0.1 (x86_64) "Homebrew" - "OpenJDK 19.0.1" /usr/local/Cellar/openjdk/19.0.1/libexec/openjdk.jdk/Contents/Home
11.0.18 (x86_64) "Homebrew" - "OpenJDK 11.0.18" /usr/local/Cellar/openjdk@11/11.0.18/libexec/openjdk.jdk/Contents/Home
/usr/local/Cellar/openjdk/19.0.1/libexec/openjdk.jdk/Contents/Home
❯ ls -al /Library/Java/JavaVirtualMachines/
total 0
drwxr-xr-x 4 root wheel 128 Jan 26 14:16 .
drwxr-xr-x 4 root wheel 128 Dec 2 20:37 ..
lrwxr-xr-x 1 root wheel 45 Jan 26 14:16 openjdk-11.jdk -> /usr/local/opt/openjdk@11/libexec/openjdk.jdk
lrwxr-xr-x 1 root wheel 42 Jan 25 19:22 openjdk.jdk -> /usr/local/opt/openjdk/libexec/openjdk.jdk
❯ cat .zshrc | grep JAVA_HOME
JAVA_HOME=$(/usr/libexec/java_home -v11)
export PATH="$JAVA_HOME/bin:$PATH"
❯ echo $JAVA_HOME
/usr/local/Cellar/openjdk@11/11.0.18/libexec/openjdk.jdk/Contents/Home
❯ java --version
openjdk 11.0.18 2023-01-17
OpenJDK Runtime Environment Homebrew (build 11.0.18+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.18+0, mixed mode)
❯ javac --version
javac 11.0.18
疑問としては、JAVA_HOME。
❯ brew info openjdk@11
If you need to have openjdk@11 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
と表示されるので、
JAVA_HOME=/usr/local/opt/openjdk@11
のほうが何か知らんけど都合がいいのではないか、
それともどっちでもいいのか、
ということ。