完全卸载后如何重新安装 Java

完全卸载后如何重新安装 Java

我完全卸载了 Java,如下所示帖子。不幸的是,我无法再重新安装 Java。

要重新安装 Java,我运行了以下命令:

$ sudo apt install default-jre

当我尝试使用以下命令检查 Java 版本时

$ java -version

我得到以下输出:

Command 'java' not found, but can be installed with:

sudo apt install default-jre            
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless

但是,当(重新)运行的时候sudo apt install default-jre,我得到:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
default-jre is already the newest version (2:1.11-68ubuntu1~18.04.1).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

任何有关如何在完全卸载后重新安装 Java 的帮助这个帖子?我已经阅读了互联网上的很多文章,但我无法解决这个问题。

命令的输出

$ apt list --installed | egrep 'jdk|jre'

结果是:

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

default-jdk/bionic-updates,bionic-security,now 2:1.11-68ubuntu1~18.04.1 amd64 [installed]
default-jdk-headless/bionic-updates,bionic-security,now 2:1.11-68ubuntu1~18.04.1 amd64 [installed,automatic]
default-jre/bionic-updates,bionic-security,now 2:1.11-68ubuntu1~18.04.1 amd64 [installed]
default-jre-headless/bionic-updates,bionic-security,now 2:1.11-68ubuntu1~18.04.1 amd64 [installed,automatic]
openjdk-11-jdk/bionic-updates,bionic-security,now 11.0.4+11-1ubuntu2~18.04.3 amd64 [installed]
openjdk-11-jdk-headless/bionic-updates,bionic-security,now 11.0.4+11-1ubuntu2~18.04.3 amd64 [installed,automatic]
openjdk-11-jre/bionic-updates,bionic-security,now 11.0.4+11-1ubuntu2~18.04.3 amd64 [installed,automatic]
openjdk-11-jre-headless/bionic-updates,bionic-security,now 11.0.4+11-1ubuntu2~18.04.3 amd64 [installed]
openjdk-8-jdk/bionic-updates,bionic-security,now 8u222-b10-1ubuntu1~18.04.1 amd64 [installed]
openjdk-8-jdk-headless/bionic-updates,bionic-security,now 8u222-b10-1ubuntu1~18.04.1 amd64 [installed]
openjdk-8-jre/bionic-updates,bionic-security,now 8u222-b10-1ubuntu1~18.04.1 amd64 [installed,automatic]
openjdk-8-jre-headless/bionic-updates,bionic-security,now 8u222-b10-1ubuntu1~18.04.1 amd64 [installed]

答案1

似乎按照这个答案,你删除了所有与 Java 相关的二进制文件,但实际上并没有删除 OpenJDK 包。你可以通过运行来重新安装它们

sudo apt install --reinstall default-jre default-jdk default-jre-headless default-jdk-headless openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless

相关内容