1. 下载jdk17
官网下载:https://www.oracle.com/java/technologies/downloads
2. 直接安装
安装完后目录会存放在下面目录下
/Library/Java/JavaVirtualMachines
111@111deMBP JavaVirtualMachines % ls
jdk-11.0.22+7 jdk-17.jdk
3. 如果你已经安装过java,需要设置环境变量更改为jdk17
vim ~/.zshrc
#export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.22+7/Contents/Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
运行并启动该环境变量
bash ~/.zshrc
source ~/.zshrc
4. 重新打开一个shell查看版本
command + T
java -version
java version "17.0.12" 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.12+8-LTS-286, mixed mode, sharing)