Mac 安装多个 jdk 踩过的坑
我是先安装了 jdk 8,然后安装了 jdk7,通过命令可以看到,默认链接的是 jdk8
bianxh:Versions bianxh$ which java
/usr/bin/java
bianxh:Versions bianxh$ ls -l /usr/bin/java
lrwxr-xr-x 1 root wheel 74 9 22 2016 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
bianxh:Versions bianxh$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
bianxh:Versions bianxh$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
配置 ~/.bash_profile
export PATH=${PATH}:/Users/bianxh/Library/Android/sdk//platform-tools
export PATH=${PATH}:/Users/bianxh/Library/Android/sdk//tools
export PATH=${PATH}:/usr/local/apache-tomcat-7.0.77/bin
export JAMES_SRC_HOME=/usr/local/james-project/james-project
# 设置 JDK 8
export JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8)
# 设置 JDK 7
export JAVA_7_HOME=$(/usr/libexec/java_home -v 1.7)
export JAVA_HOME=$JAVA_7_HOME
#alias 命令动态切换 JDK 版本
alias jdk7="export JAVA_HOME=$"JAVA_7_HOME"
alias jdk8="export JAVA_HOME=$"JAVA_8_HOME"
alias subl="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'"
alias ll='ls -al'
使用命令生效配置:
bianxh:Versions bianxh$ source ~/.bash_profile
现在查看:
bianxh:Versions bianxh$ 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)
bianxh:Versions bianxh$ /usr/libexec/java_home -v 1.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
bianxh:Versions bianxh$ /usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
以后就可以通过命令自由切换了,效果如下:
bianxh:libexec bianxh$ jdk8
bianxh:libexec bianxh$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
bianxh:libexec bianxh$ jdk7
bianxh:libexec bianxh$ 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)
当然,如果用 eclipse,注意修改 JAVA_HOME,在~/.bash_profile 中修改。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: 常见加密算法总结
下一篇: 谈谈自己对于 AOP 的了解
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论