如何从 Ubuntu 15.10 卸载某个版本的 Java?

如何从 Ubuntu 15.10 卸载某个版本的 Java?

几个月前,我在我的机器上安装了一个 Java 版本。不幸的是,我不记得怎么安装的了。:(

现在,每次我运行sudo apt-get upgradeupdate或时,autoremove我都会收到以下消息:

$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  jdk1.8.0-92
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 272 MB disk space will be freed.
Do you want to continue? [Y/n] Y
dpkg: warning: files list file for package 'libopencv-highgui2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-imgproc2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-video2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-flann2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-objdetect2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-features2d2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-core2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-contrib2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-legacy2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-calib3d2.4v5:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libopencv-ml2.4v5:amd64' missing; assuming package has no files currently installed
(Reading database ... 219411 files and directories currently installed.)
Removing jdk1.8.0-92 (1.8.092-1) ...
/var/lib/dpkg/info/jdk1.8.0-92.postrm: line 586: /usr/sbin/alternatives: No such file or directory
/var/lib/dpkg/info/jdk1.8.0-92.postrm: line 598: /usr/sbin/alternatives: No such file or directory
dpkg: error processing package jdk1.8.0-92 (--remove):
 subprocess installed post-removal script returned error exit status 127
Errors were encountered while processing:
 jdk1.8.0-92
E: Sub-process /usr/bin/dpkg returned an error code (1)

我刚刚尝试从命令行升级到 Ubuntu 16,但失败了。所以我真的需要卸载这个该死的东西,但到目前为止我读过的所有帖子都对我没用!我应该怎么做才能摆脱这个 Java 安装(然后可能正确安装它)?

答案1

要卸载 Oracle Java 8,只需按键盘上的 Ctrl+Alt+T 打开终端。打开后,运行以下命令。

sudo update-alternatives --display java

在卸载 Java 之前检查设置。接下来,删除符号链接

(将单词 (version) 替换为您的 Java 版本。输入 java -version 即可获取您的版本。因此,如果您的版本是 1.8.0-92,则需要输入sudo 更新替代方案 --remove "java" "/usr/lib/jvm/jdk1.8.0-92/bin/java"

sudo update-alternatives --remove "java" "/usr/lib/jvm/jdk<version>/bin/java"
sudo update-alternatives --remove "javac" "/usr/lib/jvm/jdk<version>/bin/javac"
sudo update-alternatives --remove "javaws" "/usr/lib/jvm/jdk<version>/bin/javaws"

验证符号链接是否已被删除

java -version
javac -version
which javaws

应谨慎输入下一个命令,以避免永久破坏您的系统。

cd /usr/lib/jvm
sudo rm -rf jdk<version>

现在编辑环境变量。

 sudo vi  /etc/environment

删除包含 JAVA_HOME 和 JRE_HOME 的行(如果有)

卸载 OpenJDK(如果已安装)。首先检查安装了哪些 OpenJDK 包。

sudo dpkg --list | grep -i jdk

要删除 openjdk:

sudo apt-get purge openjdk*

卸载OpenJDK相关的软件包。

sudo apt-get purge icedtea-* openjdk-*

检查所有 OpenJDK 包是否已被删除。

sudo dpkg --list | grep -i jdk

就这样。

相关内容