Oracle JDK

Oracle JDK,第1张

标题
  • 1. Oracle JDK
    • 1.1. MacOS 系统中切换默认 Java 版本
    • 1.2. Uninstall
      • 1.2.1. Uninstalling the JDK on macOS
    • 1.3. 问题
      • 1.3.1. 解决 `could not find java; set JAVA_HOME or ensure java is in PATH` 报错问题

1. Oracle JDK 1.1. MacOS 系统中切换默认 Java 版本
  1. 打开终端, 输入:
/usr/libexec/java_home -V

Matching Java Virtual Machines (2):
    11.0.13 (x86_64) "Oracle Corporation" - "Java SE 11.0.13" /Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home
    1.8.0_301 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home

注意: 输入命令参数区分大小写 (-v 是不对的, 必须是 -V)

如图: 3 个红框内依次为: 输入命令; 当前 Mac 已安装 JDK 目录; Mac 默认使用的 JDK 版本;

输入:

vim ~/.zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
source ~/.bash_profile
1.2. Uninstall 1.2.1. Uninstalling the JDK on macOS

参考自: 这里

To uninstall the JDK on macOS:

You must have Administrator privileges.

Note:

Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time that you perform an update of the OS.

Go to /Library/Java/JavaVirtualMachines.

Remove the directory whose name matches the following format by executing the rm command as a root user or by using the sudo tool:

/Library/Java/JavaVirtualMachines/jdk-interim.update.patch.jdk

For example, to uninstall 10 Interim 0 Update 2 Patch 1:

$ rm -rf jdk-10.0.2.1.jdk
1.3. 问题 1.3.1. 解决 could not find java; set JAVA_HOME or ensure java is in PATH 报错问题

原因: 是因为其本来配置的目录里就有 bin 了, 这样配置就导致有两个 bin 的目录, 当然就找不到了这样问题就解决了:

export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$PATH

而不是:

export JAVA_HOME=/opt/jdk/bin(错误)
export PATH=$JAVA_HOME:$PATH(错误)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/758030.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-01
下一篇 2022-05-01

发表评论

登录后才能评论

评论列表(0条)

保存