在 Amazon Linux 机器上安装 JDK 时出现错误:打开失败:没有此文件或目录

在 Amazon Linux 机器上安装 JDK 时出现错误:打开失败:没有此文件或目录

我刚买了一个新的 amazon linux 机器,想在上面安装 jdk。我按照这些命令操作,但出现了错误:

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.11.90) (amazon-62.1.11.11.90.55.amzn1-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

$ wget http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.rpm

$ ls
jdk-7u1-linux-i586.rpm

$ ls -al jdk-7u1-linux-i586.rpm 
 -rw-rw-r-- 1 username username 5307 Mar 20  2012 jdk-7u1-linux-i586.rpm

$ sudo rpm -i jdk-7u1-linux-i586.rpm 
error: open of <html> failed: No such file or directory
error: open of <head> failed: No such file or directory
error: open of <title>Unauthorized failed: No such file or directory
error: open of Request</title> failed: No such file or directory
error: open of <META failed: No such file or directory
error: open of NAME=ROBOTS failed: No such file or directory

答案1

这是因为尝试 wget 会将您重定向到 HTML 页面,大概要求您先接受他们的条款和条件。运行 wget 命令会显示以下内容:

--2013-10-14 18:16:42--  http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.rpm
Resolving download.oracle.com... 23.62.239.25, 23.62.239.8
Connecting to download.oracle.com|23.62.239.25|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.rpm [following]
--2013-10-14 18:16:43--  https://edelivery.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.rpm
Resolving edelivery.oracle.com... 23.65.6.140
Connecting to edelivery.oracle.com|23.65.6.140|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/errors/download-fail-1505220.html [following]
--2013-10-14 18:16:45--  http://download.oracle.com/errors/download-fail-1505220.html
Connecting to download.oracle.com|23.62.239.25|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5307 (5.2K) [text/html]
Saving to: ‘jdk-7u1-linux-i586.rpm’

最重要的一行就在这里:

Length: 5307 (5.2K) [text/html]

看看自述文件.mdOpsCode java cookbook 中揭示了以下内容:

IMPORTANT NOTE

As of 26 March 2012 you can no longer directly download the JDK from Oracle's 
website without using a special cookie. This cookbook uses that cookie to 
download the oracle recipe on your behalf <snipped>

但随后看着oracle.rb 配方,你会看到以下内容:

if tarball_url =~ /example.com/
  Chef::Application.fatal!("You must change the download link to your private repository. You can no longer download java directly from http://download.oracle.com without a web broswer")
end

这意味着你需要通过 apt/yum/whatever 从具有最新 JDK 7 软件包的存储库进行安装,或者转到OpenJDK 项目并从那里下载。

相关内容