如何在MacOS上安装额外的java ?我安装了jdk8,运行正常。但是现在出于开发目的,我需要安装jdk7。当试图通过DMG文件安装旧版本时,我得到一个警告,已经安装了新的java版本,安装程序退出。

    /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 ?


当前回答

在这个网站上可以找到 让我们从安装jEnv开始

Run this in the terminal brew install https://raw.github.com/gcuisinier/jenv/homebrew/jenv.rb Add jEnv to the bash profile if which jenv > /dev/null; then eval "$(jenv init -)"; fi When you first install jEnv will not have any JDK associated with it. For example, I just installed JDK 8 but jEnv does not know about it. To check Java versions on jEnv At the moment it only found Java version(jre) on the system. The * shows the version currently selected. Unlike rvm and rbenv, jEnv cannot install JDK for you. You need to install JDK manually from Oracle website. Install JDK 6 from Apple website. This will install Java in /System/Library/Java/JavaVirtualMachines/. The reason we are installing Java 6 from Apple website is that SUN did not come up with JDK 6 for MAC, so Apple created/modified its own deployment version. Similarly install JDK7 and JDK8. Add JDKs to jEnv. JDK 6: JDK 7: JDK 8: Check the java versions installed using jenv So now we have 3 versions of Java on our system. To set a default version use the command jenv local <jenv version> Ex – I wanted Jdk 1.6 to start IntelliJ jenv local oracle64-1.6.0.65 check the java version java -version

就是这样。我们现在有多个版本的java,我们可以很容易地在它们之间切换。jEnv还有其他一些特性,比如Gradle、Ant、Maven等的包装器,以及全局或本地设置JVM选项的能力。有关更多信息,请查看文档。

其他回答

我最近发现了一个叫做Jabba的Java版本管理器,它的用法与其他语言的版本管理器非常相似,比如rvm(ruby)、nvm(node)、pyenv(python)等。而且它是跨平台的,所以肯定可以在Mac上使用。

安装完成后,它将在~/目录下创建一个目录。jabba来放置你安装的所有Java版本。它“支持安装Oracle JDK(默认)/ Server JRE, Zulu OpenJDK(自0.3.0起),IBM SDK, Java技术版(自0.6.0起)和自定义url。”

他们的Github上列出了基本用法。简单总结一下:

curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh

# install Oracle JDK
jabba install 1.8 # "jabba use 1.8" will be called automatically  
jabba install 1.7 # "jabba use 1.7" will be called automatically 

# list all installed JDK's
jabba ls

# switch to a different version of JDK
jabba use 1.8

卸载jdk8,安装jdk7,然后重新安装jdk8。

我在它们之间切换的方法(在.profile中):

export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_9_HOME=$(/usr/libexec/java_home -v9)

alias java7='export JAVA_HOME=$JAVA_7_HOME'
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java9='export JAVA_HOME=$JAVA_9_HOME'

#default java8
export JAVA_HOME=$JAVA_8_HOME

然后,只需在终端中输入java7或java8即可切换版本。

(编辑:更新为Java 9添加了dylan的改进)

在这个网站上可以找到 让我们从安装jEnv开始

Run this in the terminal brew install https://raw.github.com/gcuisinier/jenv/homebrew/jenv.rb Add jEnv to the bash profile if which jenv > /dev/null; then eval "$(jenv init -)"; fi When you first install jEnv will not have any JDK associated with it. For example, I just installed JDK 8 but jEnv does not know about it. To check Java versions on jEnv At the moment it only found Java version(jre) on the system. The * shows the version currently selected. Unlike rvm and rbenv, jEnv cannot install JDK for you. You need to install JDK manually from Oracle website. Install JDK 6 from Apple website. This will install Java in /System/Library/Java/JavaVirtualMachines/. The reason we are installing Java 6 from Apple website is that SUN did not come up with JDK 6 for MAC, so Apple created/modified its own deployment version. Similarly install JDK7 and JDK8. Add JDKs to jEnv. JDK 6: JDK 7: JDK 8: Check the java versions installed using jenv So now we have 3 versions of Java on our system. To set a default version use the command jenv local <jenv version> Ex – I wanted Jdk 1.6 to start IntelliJ jenv local oracle64-1.6.0.65 check the java version java -version

就是这样。我们现在有多个版本的java,我们可以很容易地在它们之间切换。jEnv还有其他一些特性,比如Gradle、Ant、Maven等的包装器,以及全局或本地设置JVM选项的能力。有关更多信息,请查看文档。

到2023年,我在苹果芯片上无法使用brew install -cask zulu8。Brew install openjdk@8也没有。对我来说唯一有效的解决方案是brew install—cask adoptopenjdk8,然后当然是vim ~/。ZSHRC和内部:

export JAVAC_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/
export JAVA_11_HOME=$(/usr/libexec/java_home -v11)
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
alias javac8='export JAVA_HOME=$JAVAC_HOME'
alias java11='export JAVA_HOME=$JAVA_11_HOME'
alias java8='export JAVA_HOME=$JAVA_8_HOME'

从使用javac8的终端切换到新安装的(不同的)版本。注意:您可以使用与我不同的Java版本,因此这只是一个示例。

编辑:由于某种原因,它需要一些时间,一旦它被激活。在我看来,重启笔记本电脑是必要的。

我按照下面的步骤链接- https://medium.com/@euedofia/fix-default- java-versionon -maven-on-mac-os-x-156cf5930078,它对我有效。

cd /usr/local/Cellar/maven/3.5.4/bin/
nano mvn
--Update JAVA_HOME -> "${JAVA_HOME:-$(/usr/libexec/java_home)}"
mvn -version