我使用以下代码安装 jdk 8 并添加存储库
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
此后,当我尝试使用以下命令安装 Java 时,
sudo apt-get install oracle-java8-installer
我收到消息,代码响应是,
Reading package lists... Done
Building dependency tree
Reading state information... Done
oracle-java8-installer is already the newest version (8u151-1~webupd8~0).
0 upgraded, 0 newly installed, 0 to remove and 13 not upgraded.
答案1
oracle-java8-installer 已经是最新版本
这是当您尝试两次安装同一个包时收到的错误消息,因为该包已经安装。为了证明这一点,请运行以下命令来显示 oracle-java8-installer 是否已安装:
apt policy oracle-java8-installer
当您尝试安装 oracle-java8-installer 时,您收到以下错误消息:
下载完成。 正在删除过期的缓存下载... sha256sum 不匹配 jdk-8u151-linux-x64.tar.gz 未安装 Oracle JDK 8。 dpkg: 处理软件包 oracle-java8-installer (--configure) 时出错: 子进程安装后安装脚本返回错误退出状态 1 处理时遇到错误:oracle-java8-installer E: 子进程 /usr/bin/dpkg 返回错误代码 (1)
apt 说 oracle-java8-installer 已安装,但java -version
找不到 java,所以它一定由于sha256sum mismatch
错误而没有正确安装,这意味着 jdk-8u151-linux-x64.tar.gz 没有被 oracle-java8-installer 脚本正确下载。
您可能遇到与其他人相同的问题,即 oracle-java8-installer 脚本无法正常工作:当我尝试安装或删除任何软件时,都会发生错误,请有人帮助我因此请访问官方Oracle Java 9 网站,从那里下载 jdk-9.0.1_linux-x64_bin.tar.gz,然后按照此答案中的说明进行安装:如何安装 Sun/Oracle 专有的 Java JDK 6/7/8 或 JRE?。
答案2
确认其已安装的另一种方法是从终端运行此命令:
dpkg-query -l oracle-java8-installer
你应该看到这个:
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==================================-======================-======================-=========================================================================
ii oracle-java8-installer 8u151-1~webupd8~0 all Oracle Java(TM) Development Kit (JDK) 8
第二个i
表示已安装。
从man dpkg-query
:
-l, --list [package-name-pattern...]
List packages matching given pattern. If no package-name-pattern is given, list all packages in /var/lib/dpkg/status, excluding the ones
marked as not-installed (i.e. those which have been previously purged). Normal shell wildcard characters are allowed in package-name-pattern.
Please note you will probably have to quote package-name-pattern to prevent the shell from performing filename expansion. For example this
will list all package names starting with “libc6”:
dpkg-query -l 'libc6*'
The first three columns of the output show the desired action, the package status, and errors, in that order.
Desired action:
u = Unknown
i = Install
h = Hold
r = Remove
p = Purge
Package status:
n = Not-installed
c = Config-files
H = Half-installed
U = Unpacked
F = Half-configured
W = Triggers-awaiting
t = Triggers-pending
i = Installed
Error flags:
<empty> = (none)
R = Reinst-required
An uppercase status or error letter indicates the package is likely to cause severe problems. Please refer to dpkg(1) for information about
the above states and flags.
The output format of this option is not configurable, but varies automatically to fit the terminal width. It is intended for human readers,
and is not easily machine-readable. See -W (--show) and --showformat for a way to configure the output format.