在Mac上管理多个java版本最简单的方法是使用Homebrew。
在Homebrew中,使用:
Homebrew-cask来安装Java版本
Jenv来管理已安装的Java版本
如http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html所示,以下是需要遵循的步骤。
安装自酿酒
安装自制jenv
安装homebrew-cask
使用cask安装特定的Java版本(请参阅下面的“家酿-cask版本”段落)
添加这个版本给jenv来管理它
检查版本是否由jenv正确管理
对于您需要的每个Java版本,重复步骤4到6
homebrew-cask版本
添加自制/桶版本的点击到自制,使用:
brew tap homebrew/cask-versions
然后你可以查看所有可用的版本:
brew search java
然后你可以安装你喜欢的版本:
brew install --cask java7
brew install --cask java6
并像往常一样将它们添加到jenv管理。
jenv add <javaVersionPathHere>
我认为这是最干净和最简单的方法。
还有一件重要的事情需要注意,正如在Mac OS X 10.6.7中提到的Java Path Current JDK令人困惑:
For different types of JDKs or installations, you will have different
paths
You can check the paths of the versions installed using /usr/libexec/java_home -V, see How do I check if the Java JDK is installed on Mac?
On Mac OS X Mavericks, I found as following:
Built-in JRE default: /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
JDKs downloaded from Oracle: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
资源
Removing Java 8 JDK from Mac
http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html
http://sourabhbajaj.com/mac-setup/index.html
http://brew.sh
https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew#readme
http://sourabhbajaj.com/mac-setup/Homebrew/README.html
"brew tap” explained https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md
“brew versions” explained Homebrew install specific version of formula? and also https://github.com/Homebrew/homebrew-versions
https://github.com/caskroom/homebrew-cask
“cask versions”, similar to “brew versions”, see https://github.com/caskroom/homebrew-versions and also https://github.com/caskroom/homebrew-cask/issues/9447
http://www.jenv.be
https://github.com/gcuisinier/jenv