mac安装多版本jdk

最近换了一个mac pro使用,结果问题多多。比如想在一台mac上面安装多个jdk,想安装一个jdk1.8,再安装一个jdk1.7。就遇到了诸多问题。

有的人说使用 brew安装多个版本,如下:(参考:https://stackoverflow.com/questions/26252591/mac-os-x-and-multiple-java-versions

写道
brew cask install java7
brew cask install java6

 我试过了,brew确实好用,但是怎么安装java7都不行。后来查了资料,java7不在维护了,被cask从自己的库里面remove移除掉了。当然无法通过这个方法来安装了。

上面是方法一,我这里行不通。那就尝试其他方法。

参考:http://www.cnblogs.com/luodengxiong/p/5736806.html

这个URL的网址里面说了安装方法很简单,很易行。可是我这里不行啊。我安装了jdk1.8的dmg,怎么都无法安装jdk1.7的dmg。总是提示我jdk的版本已经存在,不能安装。大概其是这样的意思。

后来,多方尝试,找到了一个办法:

卸载jdk1.8,然后安装jdk1.7,再安装jdk1.8,问题就迎刃而解了。

卸载jdk参考地址:https://www.java.com/en/download/help/mac_uninstall_java.xml

卸载的方法:

写道
How do I uninstall Java on my Mac?
This article applies to:
Platform(s): Macintosh OS X
Java version(s): 7.0, 8.0
Uninstall Oracle Java using the Terminal

Note: To uninstall Java, you must have Administrator privileges and execute the remove command either as root or by using the sudo tool.

Remove one directory and one file (a symlink), as follows:

1.Click on the Finder icon located in your dock
2.Click on the Utilities folder
3.Double-click on the Terminal icon
4.In the Terminal window Copy and Paste the commands below:
    sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
    sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
    sudo rm -fr ~/Library/Application\ Support/Java
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 you perform an update of the OS.

查看jdk的java_home如下:

写道
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.0_131, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
1.7.0_80, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home

参考文章:

http://abetobing.com/blog/multiple-jdk-mac-osx-10-10-yosemite-88.html

编辑:vim ~/.bash_profile

添加内容:

写道
JAVA_8_HOME="$(/usr/libexec/java_home -v 1.8)"
JAVA_7_HOME="$(/usr/libexec/java_home -v 1.7)"
JAVA_HOME=$JAVA_7_HOME #切换java_home的时候需要手工修改一下。
export JAVA_HOME
CLASS_PATH="$JAVA_HOME/lib"
PATH=".;$PATH:$JAVA_HOME/bin"
export PATH

 然后执行: source ~/.bash_profile 使配置立即生效。

怎么切换java_home呢?看上面~/.bash_profile里面的注释。

 jdk具体的小版本问题?

我们可以通过命令 $ brew cask search java 来查看有哪些jdk的大版本可以供我们选择,如:java6、java8、java。

但是里面的这几个JDK具体的小版本是什么呢?可以通过命令 $brew cask info java8 来查看小版本号。

如:

java8的小版本号 写道
java8: 1.8.0_162-b12,0da788060d494f5095bf8624735fa2f1

猜你喜欢

转载自kanpiaoxue.iteye.com/blog/2381958