本文翻译自:How to install Java 8 on Mac
I want to do some programming with the latest JavaFX, which requires Java 8. I'm using IntelliJ 13 CE and Mac OS X 9 Mavericks. 我想使用需要Java 8的最新JavaFX进行一些编程。我正在使用IntelliJ 13 CE和Mac OS X 9 Mavericks。 I ran Oracle's Java 8 installer, and the files look like they ended up at 我运行了Oracle的Java 8安装程序,文件看起来像最终在
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk
but previous versions are at 但以前的版本在
/System/Library/Java/JavaFrameworks/jdk1.6....
Not sure why the latest installer puts this in /Library
instead of /System/Library
(nor what the difference is). 不知道为什么最新的安装程序会将它放在/Library
而不是/System/Library
(也不会有什么区别)。 But /usr/libexec/java_home
doesn't find 1.8, so all the posts I've found on how to set your current java version don't work. 但是/usr/libexec/java_home
找不到1.8,所以我找到的有关如何设置当前Java版本的所有帖子都不起作用。 I've tried adding a symbolic link to make it look like 1.8 is in the /System/Library...
path, but it doesn't help. 我尝试添加一个符号链接,使其看起来像/System/Library...
路径中的1.8,但它没有帮助。 /usr/libexec/java_home -V
still only lists the old Java 1.6. /usr/libexec/java_home -V
仍然仅列出旧的Java 1.6。
Ironically, the "Java" control panel under System Preferences shows only Java 1.8! 具有讽刺意味的是,“系统偏好设置”下的“ Java”控制面板仅显示Java 1.8!
Why doesn't Oracle's installer put it where it really goes? 为什么Oracle的安装程序没有将它放到真正的位置? And how can I work around this problem? 我该如何解决这个问题?
参考:https://stackoom.com/question/1e8hC/如何在Mac上安装Java
I also had the same problem. 我也有同样的问题。 But after little hit and trial, I was able to resolve the issue. 但是经过一番尝试之后,我得以解决此问题。
Try removing 1.6 sdk by sudo rm and restart your mac. 尝试通过sudo rm删除1.6 sdk,然后重新启动Mac。
Download again the .dmg file. 再次下载.dmg文件。 Chances are that the .dmg installer you downloaded, might be corrupt. 您下载的.dmg安装程序可能已损坏。 Install again. 重新安装。
Run following command after installation. 安装后运行以下命令。 It gives path for jdk 8. /usr/libexec/java_home -v 1.8 它提供了jdk 8的路径。/ usr / libexec / java_home -v 1.8
Also you can run and see jdk 8 folder. 您也可以运行并查看jdk 8文件夹。 The files may be hidden. 文件可能被隐藏。 ls -al /Library/Java/JavaVirtualMachines/ ls -al /图书馆/ Java / JavaVirtualMachines /
Oracle has a poor record for making it easy to install and configure Java, but using Homebrew , the latest OpenJDK (Java 13) can be installed with: Oracle在简化安装和配置Java方面的记录很差,但是使用Homebrew可以将最新的OpenJDK(Java 13)安装在:
brew cask install java
For the many use cases depending on an older version (commonly Java 8), the AdoptOpenJDK project makes it possible with an extra step. 对于依赖于较旧版本(通常为Java 8)的许多用例, AdoptOpenJDK项目通过额外的步骤即可实现。
brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8
Existing users of Homebrew may encounter Error: Cask adoptopenjdk8 exists in multiple taps
due to prior workarounds with different instructions. 现有的Homebrew用户可能会遇到Error: Cask adoptopenjdk8 exists in multiple taps
由于先前使用不同指令的解决方法,因此Error: Cask adoptopenjdk8 exists in multiple taps
。 This can be solved by fully specifying the location with brew cask install adoptopenjdk/openjdk/adoptopenjdk8
. 这可以通过使用brew cask install adoptopenjdk/openjdk/adoptopenjdk8
完全指定位置来解决。
I have applications that use both Java 7 and 8 and have to go back and forth all the time. 我有同时使用Java 7和8的应用程序,并且必须一直来回移动。
I use this script written by Johan: 我使用约翰写的这个脚本:
http://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/ http://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/
You can now set it at startup or call the script afterwards. 现在,您可以在启动时进行设置,也可以随后调用脚本。
Install the JDK for Mac. 安装Mac版JDK。
Java 7 Java 7
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Java 8 Java 8
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Note: Oracle Java 8/9/10 is no longer available for public download (license change). 注意:Oracle Java 8/9/10不再可用于公共下载(许可证更改)。
First install and update brew from Terminal: 首先从终端安装和更新brew :
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap homebrew/cask-versions
brew update
NEW as of June 2019 截至2019年6月的新功能
To install the JDKs from AdoptOpenJDK: 要从AdoptOpenJDK安装JDK:
brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8
brew cask install adoptopenjdk9
brew cask install adoptopenjdk10
brew cask install adoptopenjdk11
OLD 旧
Java 8: Java 8:
brew cask install java8
Java Latest: Java最新:
brew cask install java
An option that I am starting to really like for running applications on my local computer is to use Docker. 我开始非常喜欢在本地计算机上运行应用程序的一种选择是使用Docker。 You can simply run your application within the official JDK container - meaning that you don't have to worry about getting everything set up on your local machine (or worry about running multiple different versions of the JDK for different apps etc) 您可以简单地在官方JDK容器中运行您的应用程序-这意味着您不必担心在本地计算机上进行所有设置(或担心为不同的应用程序运行多个不同版本的JDK等)
Although this might not help you with your current installation issues, it is a solution which means you can side-step the minefield of issues related with trying to get Java running correctly on your dev machine! 尽管这可能无法帮助您解决当前的安装问题,但这是一个解决方案,这意味着您可以避开与使Java在您的开发机上正确运行有关的问题的雷区!
The benefits are: 好处是:
A very simple example: 一个非常简单的例子:
Create a Dockerfile
: 创建一个Dockerfile
:
FROM java:8
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
java:8
- to use Java 7, you could just specify: java:7
) 在这里,我们指定运行SDK的版本8的Java容器( java:8
要使用Java 7,您只需指定: java:7
) /usr/src/myapp
inside the container 我们使用容器内的目录/usr/src/myapp
映射本地目录 Create a docker-compose.yml
file: 创建一个docker-compose.yml
文件:
version: "2"
services:
java:
build: .
volumes:
- .:/usr/src/myapp
Now, assume we have this Java file: 现在,假设我们有这个Java文件:
HelloWorld.java HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
So we have the following file structure: 因此,我们具有以下文件结构:
.
|_ Dockerfile
|_ docker-compose.yml
|_ HelloWorld.java
You can do various Java things like: 您可以执行各种Java事情,例如:
compile: 编译:
docker-compose run --rm java javac HelloWorld.java
run: 跑:
docker-compose run --rm java java HelloWorld
docker-compose run
- runs a command from within the container docker-compose run
从容器内部运行命令 -rm
tells docker to remove the container once the command is finished running -rm
告诉-rm
在命令运行完成后删除容器 java
is the name of the service/container (from our docker-compose file) against which this command will run java
是将针对此命令运行的服务/容器的名称(来自我们的docker-compose文件) This is quite a cool way of dealing with running different versions of Java for different apps without making a complete mess of your local setup :). 这是处理不同应用程序运行不同版本Java的一种很酷的方法,而不会完全弄乱本地设置:)。
Here is a slightly more complex example which has Maven and a simple Spring app 这是一个稍微复杂的示例,其中包含Maven和一个简单的Spring应用程序
Disclaimer: 免责声明: