答案1
我尝试从运行 Ubuntu 20.04 的 Oracle 网站安装 Java 21(使用 Docker),似乎成功了。以下是我所做的:
docker run --name ubuntu-test --rm -it ubuntu:20.04
root@f5f73a3cc94f:/# apt update -qq &> /dev/null && apt install -y -qq curl &> /dev/null
root@f5f73a3cc94f:/# curl -s https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb -o jdk-21_linux-x64_bin.deb
root@f5f73a3cc94f:/# java --version
bash: java: command not found
root@f5f73a3cc94f:/# dpkg -i jdk-21_linux-x64_bin.deb
Selecting previously unselected package jdk-21.
(Reading database ... 4666 files and directories currently installed.)
Preparing to unpack jdk-21_linux-x64_bin.deb ...
Unpacking jdk-21 (21.0.2-ga) ...
Setting up jdk-21 (21.0.2-ga) ...
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jar to provide /usr/bin/jar (jar) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jarsigner to provide /usr/bin/jarsigner (jarsigner) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/java to provide /usr/bin/java (java) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/javac to provide /usr/bin/javac (javac) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/javadoc to provide /usr/bin/javadoc (javadoc) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/javap to provide /usr/bin/javap (javap) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jcmd to provide /usr/bin/jcmd (jcmd) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jdb to provide /usr/bin/jdb (jdb) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jdeprscan to provide /usr/bin/jdeprscan (jdeprscan) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jdeps to provide /usr/bin/jdeps (jdeps) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jfr to provide /usr/bin/jfr (jfr) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jhsdb to provide /usr/bin/jhsdb (jhsdb) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jimage to provide /usr/bin/jimage (jimage) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jinfo to provide /usr/bin/jinfo (jinfo) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jlink to provide /usr/bin/jlink (jlink) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jmap to provide /usr/bin/jmap (jmap) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jmod to provide /usr/bin/jmod (jmod) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jpackage to provide /usr/bin/jpackage (jpackage) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jps to provide /usr/bin/jps (jps) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jrunscript to provide /usr/bin/jrunscript (jrunscript) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jshell to provide /usr/bin/jshell (jshell) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jstack to provide /usr/bin/jstack (jstack) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jstat to provide /usr/bin/jstat (jstat) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jstatd to provide /usr/bin/jstatd (jstatd) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/jwebserver to provide /usr/bin/jwebserver (jwebserver) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/keytool to provide /usr/bin/keytool (keytool) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/rmiregistry to provide /usr/bin/rmiregistry (rmiregistry) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/bin/serialver to provide /usr/bin/serialver (serialver) in auto mode
update-alternatives: using /usr/lib/jvm/jdk-21-oracle-x64/lib/jexec to provide /usr/bin/jexec (jexec) in auto mode
update-alternatives: error: error creating symbolic link '/usr/share/binfmts/jar.dpkg-tmp': No such file or directory
root@f5f73a3cc94f:/# java --version
java 21.0.2 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)
如果安装 DEB 包对您不起作用,您可以尝试其他替代方法:
答案2
我在 Debian 系统上尝试安装 JDK-17 时遇到错误。我安装了它,但不小心卸载了它。重新安装后,我遇到了
错误:“错误:无法打开‘/usr/lib/jvm/jdk-17-oracle-x64/lib/jvm.cfg’”
最终,我通过使用 Synaptic 完全删除 JDK-17 解决了这个问题。
我认为sudo apt purge jdk-17
应该也有效,因为可能是剩余文件导致了问题。抱歉,我的英语很糟糕,祝你好运!
答案3
我遇到了同样的问题,但我安装了 jdk 17,没有问题。这似乎是 jdk 21 的问题。