java_Mac安装多个JDK版本并设置环境变量
JDK6、JDK7、JDK8三个版本的汇总地址:https://pan.baidu.com/s/1pKSYv8Z
安装
JDK6安装
JDK6下载地址
见网盘
安装完毕后确认版本
JavaForOSX2014-001.dmg contains Java for Mac OS X (1.6.0_65-b14-462).It will be installed to * /System/Library/Java * and /System/Library/Frameworks while Oracle Java is located at /Library/Java
>cd /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
>./bin/java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
JDK7安装
JDK7下载地址
安装完毕后确认版本
JDK7之后,安装目录比较规范化了,按着版本号在/Library/Java/JavaVirtualMachines/下自动建立子目录
/Library/Java/JavaVirtualMachines>ls -lrt
total 0
drwxr-xr-x 3 root wheel 102 11 2 15:22 jdk1.7.0_67.jdk
drwxr-xr-x 3 root wheel 102 11 3 14:58 jdk1.7.0_71.jdk
drwxr-xr-x 3 root wheel 102 4 9 13:44 jdk1.8.0_40.jdk
5
JDK8安装
安装和下载同JDK7
每次安装完后,自动更新/usr/libexec/java_home
/Users/lcz>/usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
配置多JDK版本环境
修改profile文件
1.打开~/.bash_profile,没有的话创建
vim ~/.bash_profile
2.在文件中写入,保存、退出
export JAVA_6_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
export JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
alias jdk6="export JAVA_HOME=$JAVA_6_HOME" #编辑一个命令jdk6,输入则转至jdk1.6
alias jdk7="export JAVA_HOME=$JAVA_7_HOME" #编辑一个命令jdk8,输入则转至jdk1.8
alias jdk8="export JAVA_HOME=$JAVA_8_HOME" #编辑一个命令jdk8,输入则转至jdk1.8
export JAVA_HOME=`/usr/libexec/java_home` #最后安装的版本,这样当自动更新时,始终指向最新版本
验证
/Users/lcz>. .bash_profile
/Users/lcz>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
/Users/lcz>jdk6
/Users/lcz>java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
/Users/lcz>jdk7
/Users/lcz>java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
【补充jdk1.8命令安装】
Brew下载并安装JDK1.8
brew cask search java
brew cask
install
java
java -version
create by cphmvp
email:cphmvp@163.com
爬虫技术交流_crawler QQ群 :167047843