Mac下同时安装多个版本的JDK
发布于 5 年前 作者 qjzd 2596 次浏览 最后一次编辑是 4 年前 来自 分享

安装环境

MAC10.11.1

安装所有的JDK:

Mac自带了的JDK6,安装路径:/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/。 独立JDK1.6下载地址:https://support.apple.com/kb/DL1572?locale=en_US JDK7下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html。 默认安装路径:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/ JDK8 Oracle官网下载, 默认路径为:/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/ 或者是/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/

在用户目录下自定义.bashrc

在用户目录下的新建.bash_profile配置文件,并配置以下信息

export JAVA_6_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
export JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
export JAVA_HOME=$JAVA_7_HOME
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
alias jdk7='export JAVA_HOME=$JAVA_7_HOME'
alias jdk6='export JAVA_HOME=$JAVA_6_HOME'

验证

bogon:~ xxx$ source .bash_profile bogon:~ xxx$ java -version java version "1.7.0_79" Java™ SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot™ 64-Bit Server VM (build 24.79-b02, mixed mode) bogon:~ xxx$ jdk6 bogon:~ xxx$ java -version java version "1.6.0_65" Java™ SE Runtime Environment (build 1.6.0_65-b14-468-11M4833) Java HotSpot™ 64-Bit Server VM (build 20.65-b04-468, mixed mode) bogon:~ xxx$ jdk8 bogon:~ xxx$ java -version java version "1.8.0_66" Java™ SE Runtime Environment (build 1.8.0_66-b17) Java HotSpot™ 64-Bit Server VM (build 25.66-b17, mixed mode) bogon:~ xxx$ jdk7 bogon:~ xxx$ java -version java version "1.7.0_79" Java™ SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot™ 64-Bit Server VM (build 24.79-b02, mixed mode)

重启后彻底生效

回到顶部