Downloading Java JDK on Linux via wget is shown li

2019-01-02 21:46发布

When I try to download Java from Oracle I instead end up downloading a page telling me that I need agree to the OTN license terms.

Sorry!

In order to download products from Oracle Technology Network you must agree to the OTN license terms.

Be sure that...

  • Your browser has "cookies" and JavaScript enabled.
  • You clicked on "Accept License" for the product you wish to download.
  • You attempt the download within 30 minutes of accepting the license.

How can I download and install Java?

25条回答
凸逼喃波丸
2楼-- · 2019-01-02 21:59

(Irani updated to my answer, but here's to clarify it all.)

Edit: Updated for Java 11.0.1, released in 16th October, 2018

Wget

wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.tar.gz

JRE 8u191 (no cookie flags): http://javadl.oracle.com/webapps/download/AutoDL?BundleId=235717_2787e4a523244c269598db4e85c51e0c
See the downloads in oracle.com and java.com for more.

  • -c / --continue

    Allows continuing an unfinished download.

  • --header "Cookie: oraclelicense=accept-securebackup-cookie"

    Since 15th March 2014 this cookie is provided to the user after accepting the License Agreement and is necessary for accessing the Java packages in download.oracle.com. The previous (and first) implementation in 27th March 2012 made use of the cookie gpw_e24=http%3A%2F%2Fwww.oracle.com[...]. Both cases remain unannounced to the public.

    The value doesn't have to be "accept-securebackup-cookie".

Required for Wget<1.13

  • --no-check-certificate

    Only required with wget 1.12 and earlier, which do not support Subject Alternative Name (SAN) certificates (mainly Red Hat Enterprise Linux 6.x and friends, such as CentOS). 1.13 was released in August 2011.

    To see the current version, use: wget --version | head -1

Not required

  • --no-cookies

    The combination --no-cookies --header "Cookie: name=value" is mentioned as the "official" cookie support, but not strictly required here.

cURL

curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.tar.gz
  • -L / --location

    Required for cURL to redirect through all the mirrors.

  • -C / --continue-at -

    See above. cURL requires the dash (-) in the end.

  • -b / --cookie "oraclelicense=accept-securebackup-cookie"

    Same as -H / --header "Cookie: ...", but accepts files too.

  • -O

    Required for cURL to save files (see author's comparison for more differences).

查看更多
还你笑眼,
3楼-- · 2019-01-02 22:00

oracle-java-download is a project on GitHub that allows you to create download links for JDK 8 and JDK 9 which you can use for further processing e.g in automated build or deployment processes.

It requires Linux, Docker and a JDK >= 8 to run.

查看更多
We Are One
4楼-- · 2019-01-02 22:00

As already posted here: https://stackoverflow.com/a/41718895/4370196

Update for JDK 8 Update 121

Since Oracle inserted some md5hash in their download links, one cannot automatically assemble a download link for command line.

So I tinkered some nasty bash command line to get the latest jdk download link, download it and directly install via rpm. For all who are interested:

wget -q http://www.oracle.com/technetwork/java/javase/downloads/index.html -O ./index.html && grep -Eoi ']+>' index.html | grep -Eoi '/technetwork/java/javase/downloads/jdk8-downloads-[0-9]+.html' | (head -n 1) | awk '{print "http://www.oracle.com"$1}' | xargs wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" -O index.html -q && grep -Eoi '"filepath":"[^"]+jdk-8u[0-9]+-linux-x64.rpm"' index.html | grep -Eoi 'http:[^"]+' | xargs wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" -q -O ./jdk8.rpm && sudo rpm -i ./jdk8.rpm

The bold part should be replaced by the package of your liking.

查看更多
Explosion°爆炸
5楼-- · 2019-01-02 22:04

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.rpm?AuthParam=1516282527_40effcfefd78d78bce12c0a4030a1b05"

查看更多
至少爱过!
6楼-- · 2019-01-02 22:04

UPDATED FOR Oracle JDK 11

wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/11+28/55eed80b163941c8885ad9298e6d786a/jdk-11_linux-x64_bin.tar.gz

UPDATED FOR JDK 10.0.2

wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/10.0.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.tar.gz

UPDATED FOR JDK 10.0.1

wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/10.0.1+10/fb4372174a714e6b8c52526dc134031e/jdk-10.0.1_linux-x64_bin.tar.gz

UPDATED FOR JDK 9 it looks like you can download it now directly from java.net without sending a header

wget http://download.java.net/java/GA/jdk9/9/binaries/jdk-9+181_linux-x64_bin.tar.gz

UPDATED FOR JDK 8u191

TAR GZ:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3a%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk8-downloads-2133151.html; oraclelicense=accept-securebackup-cookie;" "https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz"

RPM:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3a%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk8-downloads-2133151.html; oraclelicense=accept-securebackup-cookie;" "https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm"

UPDATED FOR JDK 8u131

RPM:

  wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm

TAR GZ:

 wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz

RPM using curl:

 curl -v -j -k -L -H "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm > jdk-8u112-linux-x64.rpm

In all cases above, subst 'i586' for 'x64' to download the 32-bit build.

  • -j -> junk cookies
  • -k -> ignore certificates
  • -L -> follow redirects
  • -H [arg] -> headers

curl can be used in place of wget.

UPDATE FOR JDK 7u79

TAR GZ:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz

RPM using curl:

curl -v -j -k -L -H "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm > jdk-7u79-linux-x64.rpm

Once again, make sure you specify the correct URL for the version you are downloading. You can find the URL here: Oracle JDK download site

ORIGINAL ANSWER FROM 9th June 2012

If you are looking to download the Oracle JDK from the command line using wget, there is a workaround. Run the wget command as follows:

wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com" "http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz"

Be sure to replace the download link with the correct one for the version you are downloading.

查看更多
几时共舞
7楼-- · 2019-01-02 22:06

Instead of using for every new Java version a new link or changing existing scripts, I was looking for a more generic way to automate the download of the required Java packages and later installation via yum localinstall ${JAVA_ENVIRONMENT}-${JAVA_VERSION}-linux-x64.rpm.

I've used a somehow trivial approach similar to manual/user action to find the package and to download it. I am also pretty sure that one will find a more elegant way to do it by using other tools like egrep, awk, etc.., so leave it as an example here:

#!/bin/bash

### Proxy settings
# If there is a company proxy 

PROXY="my.proxy.local:8080"
PROXY_TYPE="--proxy-ntlm" # or leave empty with ""
USER="user"
PASS='pass'

### Find out the links to JRE and JDK 
# To do so, got to the page http://www.oracle.com/technetwork/java/javase/downloads/

BASE_URL="technetwork/java/javase/downloads"

# Put the whole page into a single string/line

BASE_URL_OUTPUT="$(curl -s -k ${PROXY_TYPE} -x "http://${USER}:${PASS}@${PROXY}" -L0 http://www.oracle.com/${BASE_URL}/)"

# Define the environments to download 

JAVA_ENVIRONMENTS=("JRE" "JDK") # ! yet "SERVER-JRE"

for JAVA_ENVIRONMENT in "${JAVA_ENVIRONMENTS[@]}"
do

echo
echo "JAVA_ENVIRONMENT="$JAVA_ENVIRONMENT
echo

for (( JAVA_BASE_VERSION = 8; JAVA_BASE_VERSION <= 10; JAVA_BASE_VERSION += 2 ))  
do

echo "JAVA_BASE_VERSION="$JAVA_BASE_VERSION

### "Read the page"
# and follow the links for the package interested in 

DOWNLOAD_SITE="$(echo $BASE_URL_OUTPUT | grep -m 1 -io "${JAVA_ENVIRONMENT}${JAVA_BASE_VERSION}-downloads-[0-9]*.html" -- | tail -1)"
echo "DOWNLOAD_SITE="$DOWNLOAD_SITE

### Gather the necessary download links
# To do so, following the link to the download site
# reading and accept the license 
# 
# ... the greedy regular expression is to address the different syntax of the links
# and already prepared for OR .gz files 

DOWNLOAD_LINK_OUTPUT="$(curl -s -k ${PROXY_TYPE} -x "http://${USER}:${PASS}@${PROXY}" -L -j -H "Cookie: oraclelicense=accept-securebackup-cookie" http://www.oracle.com/${BASE_URL}/${DOWNLOAD_SITE} |  grep -io "filepath.*${JAVA_ENVIRONMENT}-[${JAVA_BASE_VERSION}].*linux[-_]x64[._].*\(rpm\)" -- | cut -d '"' -f 3 | tail -1)"

# and echo out the link

echo "DOWNLOAD_LINK_OUTPUT="$DOWNLOAD_LINK_OUTPUT

done

done

Since the download links are available now, one may proceed further with wget or curl.

查看更多
登录 后发表回答