我尝试了几种安装方法openjdk
,这是我安装时得到的:java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)
但是当我执行 javac -version 时,它说找不到 javac。我执行以下操作:sudo apt-get install default-jre
The following packages have unmet dependencies:
default-jre : Depends: default-jre-headless (= 2:1.10-63ubuntu1~02) but 2:1.11-68ubuntu1~18.04.1 is to be installed
Depends: openjdk-11-jre but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
然后:sudo apt-get install default-jdk
default-jdk : Depends: default-jre (= 2:1.10-63ubuntu1~02) but it is not going to be installed
Depends: default-jdk-headless (= 2:1.10-63ubuntu1~02) but it is not going to be installed
Depends: openjdk-11-jdk but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
然后:sudo update-alternatives --config java
替代 java 有 2 种选择(提供 /usr/bin/java)。
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
如何解决这些问题并正确安装 java 和 javac?
我可以通过在错误消息中下载所需的版本来缓解此问题。就我而言,我从这里下载并安装了 openjdk-11-jdk_11.0.9.1+1-0ubuntu1~18.04_amd64.deb 及其所有必需的依赖项:https ://ubuntu.pkgs.org/18.04/ubuntu-updates -main-amd64/openjdk-11-jdk_11.0.9.1+1-0ubuntu1~18.04_amd64.deb.html。