一、jdk安装路径
/Library/Java/JavaVirtualMachines/
二、jdk配置
1、创建.bash_profile配置文件(已经有该文件就直接修改)
vim ~/.bash_profile
1
2、添加以下内容:
export JAVA7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
export JAVA8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
export JAVA10_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
#默认jdk
export JAVA_HOME=$JAVA8_HOME
1
2
3
4
5
3、修改.bash_aliases文件,增加以下内容
alias jdk7='export JAVA_HOME=$JAVA7_HOME'
alias jdk8='export JAVA_HOME=$JAVA8_HOME'
alias jdk10='export JAVA_HOME=$JAVA10_HOME'
1
2
3
4、执行以下命令,使配置立即生效。
source .bash_profile
source .bash_aliases
1
2
三、jdk切换测试
zhanglei:~ zhanglei$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
zhanglei:~ zhanglei$ jdk7
zhanglei:~ zhanglei$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
zhanglei:~ zhanglei$ jdk10
zhanglei:~ zhanglei$ java -version
java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
网友评论