Mac OS X 和多个 Java 版本 [英] Mac OS X and multiple Java versions
问题描述
如何在 MacOS 上安装额外的 java?我安装了 jdk8,效果很好.但现在我需要一个 jdk7 安装用于开发目的.尝试通过 DMG 文件安装旧版本时,我收到一条警告,提示已经安装了较新版本的 java 并且安装程序退出.
How can I install an additional java on MacOS? I installed jdk8 and that works fine. But now I need a jdk7 installation for development purposes. When trying to install the old version via DMG file, i get a warning, that there is already a newer version of java installed and the installer quits.
/usr/libexec/java_home -verbose
Matching Java Virtual Machines (1):
1.8.0_20, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
除了这个还怎么安装jdk7?
How to install jdk7 in addition to this one?
推荐答案
在 Mac 上管理多个 Java 版本的最简洁方法是使用 <代码>自制软件.
The cleanest way to manage multiple java versions on Mac is to use Homebrew
.
在 Homebrew
中,使用:
homebrew-cask
安装java版本jenv
管理已安装的 java 版本
homebrew-cask
to install the versions of javajenv
to manage the installed versions of java
如http://hanxue 所见-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html ,这些是要遵循的步骤.
As seen on http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html , these are the steps to follow.
- 安装自制软件
- 安装自制软件 jenv
- 安装 homebrew-cask
- 使用 cask 安装特定的 java 版本(请参阅下面的homebrew-cask 版本"段落)
- 为 jenv 添加此版本以进行管理
- 检查版本是否由 jenv 正确管理
- 为您需要的每个 Java 版本重复步骤 4 到 6
<小时>
自制酒桶版本
添加 homebrew/cask-versions
点击以自制程序使用:
homebrew-cask versions
Add the homebrew/cask-versions
tap to homebrew using:
brew tap homebrew/cask-versions
然后你可以查看所有可用的版本:
Then you can look at all the versions available:
brew search java
然后你可以安装你喜欢的版本:
Then you can install the version(s) you like:
brew cask install java7
brew cask install java6
并像往常一样将它们添加到 jenv 管理.
And add them to be managed by jenv as usual.
jenv add <javaVersionPathHere>
我认为这是最干净的&最简单的方法.
I think this is the cleanest & simplest way to go about it.
另一个需要注意的重要事项,如Mac OS X 10.6.7 Java 路径当前 JDK 令人困惑 :
Another important thing to note, as mentioned in Mac OS X 10.6.7 Java Path Current JDK confusing :
对于不同类型的 JDK 或安装,您将有不同的路径
For different types of JDKs or installations, you will have different paths
您可以使用/usr/libexec/java_home -V
查看安装版本的路径,参见如何检查Mac上是否安装了Java JDK?
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?
在 Mac OS X Mavericks 上,我发现如下:
On Mac OS X Mavericks, I found as following:
1) 内置 JRE 默认:/Library/Internet插件/JavaAppletPlugin.plugin/Contents/Home
1) Built-in JRE default: /Library/Internet
Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
2) 从 Apple 下载的 JDK:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
2) JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
3) 从 Oracle 下载的 JDK:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
3) JDKs downloaded from Oracle: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
<小时>
资源
- 从 Mac 中删除 Java 8 JDK
- 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"解释了 https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md
- brew 版本"解释了 Homebrew 安装特定版本的公式? 和还有 https://github.com/Homebrew/homebrew-versions
- https://github.com/caskroom/homebrew-cask
- cask versions",类似于brew versions",参见https://github.com/caskroom/homebrew-versions 和 https://github.com/caskroom/homebrew-cask/issues/9447
- http://www.jenv.be
- https://github.com/gcuisinier/jenv
- 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
Resources
这篇关于Mac OS X 和多个 Java 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!