赞
踩
摘要:一台MAC笔记本安装所有的主流的JDK
-
- localhost:~ xxx$ java -version
- java version "1.8.0_192"
- Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
- Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
- localhost:~ xxx$ jdk11
- localhost:~ xxx$ java -version
- java version "11.0.19" 2023-04-18 LTS
- Java(TM) SE Runtime Environment 18.9 (build 11.0.19+9-LTS-224)
- Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.19+9-LTS-224, mixed mode)
- localhost:~ xxx$ jdk17
- localhost:~ xxx$ java -version
- java version "17.0.2" 2022-01-18 LTS
- Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
- Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
- localhost:~ xxx$
关键词:jdk17 jdk11 jdk8 MAC
最近基本都要求使用jdk17 jdk11 用jdk8的也逐渐在升级
那么开发机就要安装多套jdk
在已经安装8的基础上安装17
命令示例
- Last login: Sun Apr 23 10:07:05 on console
-
- The default interactive shell is now zsh.
- To update your account to use zsh, please run `chsh -s /bin/zsh`.
- For more details, please visit https://support.apple.com/kb/HT208050.
- # 查看本机所有的jdk
- localhost:~ username$ /usr/libexec/java_home -V
- Matching Java Virtual Machines (3):
- 17.0.2, x86_64: "Java SE 17.0.2" /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
- 1.8.0_271, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
- 1.8.0_192, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
-
- /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
-
- # 接下来,打开终端,输入vim ~/.bash_profile,编辑配置文件
- localhost:~ username$ vim ~/.bash_profile
- # 在配置文件中,配置成以下内容: 见示例
-
- # 输入完成,按esc键,输入:wq保存退出后执行命令:source ~/.bash_profile
- localhost:~ username$ source ~/.bash_profile
- localhost:~ username$
- localhost:~ username$ java -version
- java version "1.8.0_192"
- Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
- Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
- localhost:~ username$ jdk17
- localhost:~ username$ java -version
- java version "17.0.2" 2022-01-18 LTS
- Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
- Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
- localhost:~ username$ java -version
- java version "17.0.2" 2022-01-18 LTS
- Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
- Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
- localhost:~ username$
-
配置示例
- # 配置jdk路径
- export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
- export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
-
- # 设置默认jdk版本
- export JAVA_HOME=$JAVA_8_HOME
-
- # 配置alias命令动态切换jdk版本
- alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
- alias jdk17="export JAVA_HOME=$JAVA_17_HOME"
继续安装11
本人MAC只能安装“x64 DMG Installer”
修改配置
-
- export GOROOT=/usr/local/go
- export PATH=$PATH:$GOROOT/bin
- # 配置jdk路径
- export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
- export JAVA_11_HOME=/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
- export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
-
- # 设置默认jdk版本
- export JAVA_HOME=$JAVA_8_HOME
-
- # 配置alias命令动态切换jdk版本
- alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
- alias jdk11="export JAVA_HOME=$JAVA_11_HOME"
- alias jdk17="export JAVA_HOME=$JAVA_17_HOME"
-
- export PATH=$PATH:$JAVA_HOME/bin
- export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
- export PATH=$PATH:/usr/local/mysql/bin
- ~
- -- INSERT --
命令行操作
- Last login: Fri May 5 17:06:51 on ttys000
-
- The default interactive shell is now zsh.
- To update your account to use zsh, please run `chsh -s /bin/zsh`.
- For more details, please visit https://support.apple.com/kb/HT208050.
- localhost:~ xxx$ /usr/libexec/java_home -V
- Matching Java Virtual Machines (4):
- 17.0.2, x86_64: "Java SE 17.0.2" /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
- 11.0.19, x86_64: "Java SE 11.0.19" /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
- 1.8.0_271, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
- 1.8.0_192, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
-
- /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
- localhost:~ xxx$ vim ~/.bash_profile
- localhost:~ xxx$ source ~/.bash_profile
- localhost:~ xxx$ java -version
- java version "1.8.0_192"
- Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
- Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
- localhost:~ xxx$ jdk11
- localhost:~ xxx$ java -version
- java version "11.0.19" 2023-04-18 LTS
- Java(TM) SE Runtime Environment 18.9 (build 11.0.19+9-LTS-224)
- Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.19+9-LTS-224, mixed mode)
- localhost:~ xxx$ jdk17
- localhost:~ xxx$ java -version
- java version "17.0.2" 2022-01-18 LTS
- Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
- Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
- localhost:~ xxx$
默认已经有了8,17
继续添加11
REF
如何在MAC M1上同时安装JDK8和JDK17_fan儿的博客-CSDN博客
Mac安装多个版本JDK并实现切换【保姆级笔记超简单】_brew jdk17_今天又有什么bug的博客-CSDN博客
祝大家开发愉快
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。