当前位置:   article > 正文

综述:MAC 多JDK配置_mac 配置jdk17

mac 配置jdk17

摘要:一台MAC笔记本安装所有的主流的JDK

  1. localhost:~ xxx$ java -version
  2. java version "1.8.0_192"
  3. Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
  4. Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
  5. localhost:~ xxx$ jdk11
  6. localhost:~ xxx$ java -version
  7. java version "11.0.19" 2023-04-18 LTS
  8. Java(TM) SE Runtime Environment 18.9 (build 11.0.19+9-LTS-224)
  9. Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.19+9-LTS-224, mixed mode)
  10. localhost:~ xxx$ jdk17
  11. localhost:~ xxx$ java -version
  12. java version "17.0.2" 2022-01-18 LTS
  13. Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
  14. Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
  15. localhost:~ xxx$

关键词:jdk17 jdk11 jdk8 MAC


最近基本都要求使用jdk17 jdk11 用jdk8的也逐渐在升级

那么开发机就要安装多套jdk

在已经安装8的基础上安装17

Java Downloads | Oracle

命令示例

  1. Last login: Sun Apr 23 10:07:05 on console
  2. The default interactive shell is now zsh.
  3. To update your account to use zsh, please run `chsh -s /bin/zsh`.
  4. For more details, please visit https://support.apple.com/kb/HT208050.
  5. # 查看本机所有的jdk
  6. localhost:~ username$ /usr/libexec/java_home -V
  7. Matching Java Virtual Machines (3):
  8. 17.0.2, x86_64: "Java SE 17.0.2" /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
  9. 1.8.0_271, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
  10. 1.8.0_192, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
  11. /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
  12. # 接下来,打开终端,输入vim ~/.bash_profile,编辑配置文件
  13. localhost:~ username$ vim ~/.bash_profile
  14. # 在配置文件中,配置成以下内容: 见示例
  15. # 输入完成,按esc键,输入:wq保存退出后执行命令:source ~/.bash_profile
  16. localhost:~ username$ source ~/.bash_profile
  17. localhost:~ username$
  18. localhost:~ username$ java -version
  19. java version "1.8.0_192"
  20. Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
  21. Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
  22. localhost:~ username$ jdk17
  23. localhost:~ username$ java -version
  24. java version "17.0.2" 2022-01-18 LTS
  25. Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
  26. Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
  27. localhost:~ username$ java -version
  28. java version "17.0.2" 2022-01-18 LTS
  29. Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
  30. Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
  31. localhost:~ username$

配置示例

  1. # 配置jdk路径
  2. export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
  3. export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
  4. # 设置默认jdk版本
  5. export JAVA_HOME=$JAVA_8_HOME
  6. # 配置alias命令动态切换jdk版本
  7. alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
  8. alias jdk17="export JAVA_HOME=$JAVA_17_HOME"

继续安装11

下载地址:Java Downloads | Oracle

本人MAC只能安装“x64 DMG Installer”

修改配置

  1. export GOROOT=/usr/local/go
  2. export PATH=$PATH:$GOROOT/bin
  3. # 配置jdk路径
  4. export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
  5. export JAVA_11_HOME=/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
  6. export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
  7. # 设置默认jdk版本
  8. export JAVA_HOME=$JAVA_8_HOME
  9. # 配置alias命令动态切换jdk版本
  10. alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
  11. alias jdk11="export JAVA_HOME=$JAVA_11_HOME"
  12. alias jdk17="export JAVA_HOME=$JAVA_17_HOME"
  13. export PATH=$PATH:$JAVA_HOME/bin
  14. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  15. export PATH=$PATH:/usr/local/mysql/bin
  16. ~
  17. -- INSERT --

命令行操作

  1. Last login: Fri May 5 17:06:51 on ttys000
  2. The default interactive shell is now zsh.
  3. To update your account to use zsh, please run `chsh -s /bin/zsh`.
  4. For more details, please visit https://support.apple.com/kb/HT208050.
  5. localhost:~ xxx$ /usr/libexec/java_home -V
  6. Matching Java Virtual Machines (4):
  7. 17.0.2, x86_64: "Java SE 17.0.2" /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
  8. 11.0.19, x86_64: "Java SE 11.0.19" /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
  9. 1.8.0_271, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
  10. 1.8.0_192, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home
  11. /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home
  12. localhost:~ xxx$ vim ~/.bash_profile
  13. localhost:~ xxx$ source ~/.bash_profile
  14. localhost:~ xxx$ java -version
  15. java version "1.8.0_192"
  16. Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
  17. Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
  18. localhost:~ xxx$ jdk11
  19. localhost:~ xxx$ java -version
  20. java version "11.0.19" 2023-04-18 LTS
  21. Java(TM) SE Runtime Environment 18.9 (build 11.0.19+9-LTS-224)
  22. Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.19+9-LTS-224, mixed mode)
  23. localhost:~ xxx$ jdk17
  24. localhost:~ xxx$ java -version
  25. java version "17.0.2" 2022-01-18 LTS
  26. Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
  27. Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
  28. localhost:~ xxx$

默认已经有了8,17

继续添加11

 

REF

如何在MAC M1上同时安装JDK8和JDK17_fan儿的博客-CSDN博客

Mac安装多个版本JDK并实现切换【保姆级笔记超简单】_brew jdk17_今天又有什么bug的博客-CSDN博客

祝大家开发愉快 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/411044
推荐阅读
相关标签
  

闽ICP备14008679号