Fork me on GitHub

Ivan-Site.com

Download Oracle Java JRE & JDK using a script

Oracle has recently disallowed direct downloads of java from their servers (without going through the browser and agreeing to their terms, which you can look at here: Oracle terms). So, if you try:

wget "http://download.oracle.com/otn-pub/java/jdk/7u4-b20/jdk-7u4-linux-x64.tar.gz"

you will receive a page with "In order to download products from Oracle Technology Network you must agree to the OTN license terms" error message.

This can be rather troublesome for setting up servers with automated scripts.

Luckily, it seems that a single cookie is all that is needed to bypass this (you still have to agree to the terms to install):

Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie

So, if you want to download jdk7u4 for 64-bit Linux (e.g., Ubuntu) using wget, you can use:

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/7u4-b20/jdk-7u4-linux-x64.tar.gz"

Just for reference, here are the links to the current (at the time of posting) downloads of JDK and JRE

UPDATE: instead of having new post for each JDK/JRE update I'll just keep updating this one

UPDATE 2: Seems that you now need the --no-check-certificate flag for wget or you'll get a "cannot verify edelivery.oracle.com's certificate" error.

UPDATE 3: Starting with 7u51 they changed the cookie name, it's now "oraclelicense", thank you Yngve for posting in the comments - I updated the commands to include both cookies.

JDK 8u112

  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-i586.rpm
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-i586.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.rpm
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b16/jdk-8u112-macosx-x64.dmg
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-solaris-sparcv9.tar.Z
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-solaris-sparcv9.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-solaris-x64.tar.Z
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-solaris-x64.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-windows-i586.exe
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-windows-x64.exe

JRE 8u112

  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-linux-i586.rpm
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-linux-i586.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-linux-x64.rpm
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-linux-x64.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b16/jre-8u112-macosx-x64.dmg
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b16/jre-8u112-macosx-x64.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-solaris-sparcv9.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-solaris-x64.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-windows-i586-iftw.exe
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-windows-i586.exe
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-windows-i586.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-windows-x64.exe
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jre-8u112-windows-x64.tar.gz

Server JRE 8u112

  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/server-jre-8u112-linux-x64.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/server-jre-8u112-solaris-sparcv9.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/server-jre-8u112-solaris-x64.tar.gz
  • http://download.oracle.com/otn-pub/java/jdk/8u112-b15/server-jre-8u112-windows-x64.tar.gz

Posted Sat 05 May 2012 by Ivan Dyedov in Java (Java, Ubuntu, Linux)

65 comments

  • Avatar
    arielnmz 2015-06-17T02:53:55

    I have to note though that in order to use curl you have to enable the "follow redirects" option (-L) or else it won't work. Thanks for this post it was very helpful.

  • Avatar
    Inet Q 2015-03-29T04:08:41

    Completely automated:

    https://github.com/inetquestio...

    • Avatar
      Richard Smith-Unna 2016-01-10T15:47:19

      this is by far the easiest way to do it! all the other comments are irrelevant in light of this one

  • Avatar
    Reiner030 2014-07-30T20:06:08

    mmh... seems again broken...:

    + wget --no-cookies --no-check-certificate --header 'Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie' http://www.oracle.com/technetw... -O jdk-7u65-linux-x64.tar.gz
    --2014-07-30 21:54:39-- http://www.oracle.com/technetw...
    Resolving www.oracle.com (www.oracle.com)... 23.63.134.140
    Connecting to www.oracle.com (www.oracle.com)|23.63.134.140|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 68457 (67K) [text/html]

    EDIT: also tested with Cookie value gpw_e24=<url of="" html="" page=""> which I found in my Firefox Cookie information page and also with the .testSessionCookie=Enabled - always got html downloaded instead of the archive by wget.

    • Avatar
      Ivan Dyedov 2014-07-30T20:18:37

      still works fine for me, are you sure you're using the correct url? disqus cut it off, but it starts with "http://www.oracle.com/technetw" which doesn't seem right

      • Avatar
        Reiner030 2014-07-30T20:57:37

        ah, yes. sorry... that was a wrong variable setup as request...

        here my full download script for Debian Packaging... I use Debian package "make-jpkg" (slight modified to get no openjdk installed) to build the java package:

        #!/bin/bash
        JAVA_PAGE=`curl http://www.oracle.com/technetw... 2>/dev/null | sed -ne 's/.*href="\([/a-z]*jdk7-downloads-[0-9]*\.html\)".*/\1/p'| uniq`
        JAVA_TAR=`curl http://www.oracle.com$JAVA_PAGE 2>/dev/null | sed -ne "s/.*\['files'\]\['\(jdk-7.*-linux-x64.tar.gz\)'.*/\1/p"`
        JAVA_URL=`curl http://www.oracle.com$JAVA_PAGE 2>/dev/null | sed -ne 's/.*"filepath":"\(http.*jdk-7.*-linux-x64.tar.gz\)".*/\1/p'`
        JAVA_COOKIE_VAL=`echo "http://www.oracle.com$JAVA_PAGE" | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/$/%24/g' -e 's/\&/%26/g' -e "s/'/%27/g" -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2A/g' -e 's/+/%2B/g' -e 's/,/%2C/g' -e 's/-/%2D/g' -e 's#/#%2F#g' -e 's/:/%3A/g' -e 's/;/%3B/g' -e 's//%3E/g' -e 's/?/%3F/g' -e 's/@/%40/g' -e 's/\[/%5B/g' -e 's/\\\/%5C/g' -e 's/\]/%5D/g' -e 's/\^/%5E/g' -e 's/_/%5F/g' -e 's/\`/%60/g' -e 's/{/%7B/g' -e 's/|/%7C/g' -e 's/}/%7D/g' -e 's/~/%7E/g' -e 's/%24$//'`

        test -f $JAVA_TAR && TAR=$JAVA_TAR
        if test ! -f "$TAR"
        then
        echo "Downloading actual Java packet from"
        echo "http://www.oracle.com$JAVA_PAGE"
        echo "to $TAR"
        wget --no-cookies --no-check-certificate \
        --header "Cookie: gpw_e24=${JAVA_COOKIE_VAL}; oraclelicense=accept-securebackup-cookie;" \
        ${JAVA_URL} -O ${JAVA_TAR}
        fi

        DEBANIZED=`echo $TAR | sed -e "s/tar.gz/debian/"`
        DEB=`test -f $DEBANIZED && cat $DEBANIZED`

        if dpkg -I $DEB >/dev/null 2>&1

        then
        echo "Actual Debian Packet $DEB found."
        else

        echo "Making Java Debian Package..."
        DEB=`echo y | make-jpkg $TAR 2>/dev/null | sed -ne "s/install the package as root (e.g. dpkg -i \(.*\))./\1/p"`
        echo $DEB > $DEBANIZED
        echo "Debian Packet $DEB created."
        fi

        echo $DEBANIZED
        echo $DEB

        exit

  • Avatar
    Reiner030 2014-07-16T18:52:27

    JAVA_PAGE=`curl http://www.oracle.com/technetw... 2>/dev/null | sed -ne 's/.*href="\([/a-z]*jdk7-downloads-[0-9]*\.html\)".*/\1/p'| uniq`
    JAVA_TAR=`curl http://www.oracle.com$JAVA_PAGE 2>/dev/null | sed -ne "s/.*\['files'\]\['\(jdk-7.*-linux-x64.tar.gz\)'.*/\1/p"`
    JAVA_URL=`curl http://www.oracle.com$JAVA_PAGE 2>/dev/null | sed -ne 's/.*"filepath":"\(http.*jdk-7.*-linux-x64.tar.gz\)".*/\1/p'`

    $ echo $JAVA_PAGE
    /technetwork/java/javase/downloads/jdk7-downloads-1880260.html
    $JAVA_TAR
    jdk-7u65-linux-x64.tar.gz
    $ echo $JAVA_URL
    http://download.oracle.com/otn...

  • Avatar
    Chris 2014-06-07T09:53:21

    Can confirm that you can download the latest Java 8 using:

    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..." -O "jdk-8u5-linux-x64.rpm"

  • Avatar
    Chris 2014-04-21T08:31:45

    Has anyone else found the oracle download URL to be very unreliable? This makes it difficult to use Oracle JDK in automated devops scripts.

  • Avatar
    Yngve 2014-03-15T13:35:49

    I got it working today by replacing setting a different header (the gpw_e24 didn't work): --header "Cookie: oraclelicense=accept-securebackup-cookie"

    • Avatar
      Ivan Dyedov 2014-03-15T15:23:58

      Thank you, I updated the command to include both cookies

  • Avatar
    O'Shaughnessy 2014-03-12T18:33:30

    The latest release of Java 7 is 7u51, so this URL worked for me:

    http://download.oracle.com/otn...

  • Avatar
    webofmars 2014-03-12T10:13:15

    seems it doesn't work anymore. now you HAVE to have an oracla account

    • Avatar
      Ivan Dyedov 2014-03-12T18:29:24

      still works for me with wget

  • Avatar
    Tom 2014-02-26T00:45:59

    I love you also!!

  • Avatar
    Azathoth 2014-02-21T09:10:51

    I love you!

  • Avatar
    Pazzo 2014-01-07T22:24:42

    For anyone who got their URL from the download page (http://www.oracle.com/technetw...

    e.g. http://download.oracle.com/otn...

    You just need to chage s/otn/otn-pub/ to change it to the direct link.

    e.g. http://download.oracle.com/otn...

  • Avatar
    Biju 2014-01-01T10:18:32

    Thank you man ... helped a lot

  • Avatar
    Khalil 2013-11-02T14:11:33

    what is difference in between " jre-7u45-windows-x64.tar.gz" and " jre-7u45-windows-x64.exe"

    • Avatar
      Ivan Dyedov 2015-09-05T00:21:40

      I think the exe is an installer, while tar.gz just has the binaries in compressed format

  • Avatar
    Srihari 2013-10-30T08:52:46

    Wow, this helped a lot and save my time. Thanks.

  • Avatar
    pritesh 2013-10-18T11:01:23

    Thanks man.. it is very useful post.

  • Avatar
    Richard Murray 2013-10-17T11:32:32

    Hi does anyone know how to do this in Groovy or Java? I've tried the following Groovy code but I get an EmptyInputStream returned.

    def address = "http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jre-7u45-windows-x64.tar.gz"
    def file = new FileOutputStream(address.tokenize("/")[-1])
    def out = new BufferedOutputStream(file)
    URL url = new URL(address);
    HttpURLConnection conn = url.openConnection();
    //proxy settings
    System.setProperty("http.proxyHost", proxyHost);
    System.setProperty("http.proxyPort", proxyPort);

    conn.setFollowRedirects(true);
    //conn.setRequestProperty("Cookie", "gpw_e24=http%3A%2F%2Fwww.oracle.com%2F");
    conn.setRequestProperty("Cookie", "gpw_e24=http");
    conn.setAllowUserInteraction(false);
    conn.connect();

    InputStream is = conn.getInputStream();
    byte[] buffer = new byte[BUFFER_SIZE];
    int numRead = 0;
    while ((numRead = is.read(buffer)) != -1) {
    out.write(buffer, 0, numRead);
    }

    out.close()
    println "done"

    • Avatar
      Richard Murray 2013-10-25T13:32:00

      I managed to get this working in a Groovy script as follows (thought I'd post if anyone is interested). It seems the Java API for HttpUrlConnection doesn't automatically follow redirects if the protocol changes (e.g. from http to https), so you need code to handle that. The example below isn't very elegant but works and should provide a starting point for anyone else trying this.


      import java.net.HttpURLConnection;
      import java.net.URLConnection;

      Downloader downloader = new Downloader()
      downloader.download("http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jre-7u45-windows-x64.tar.gz");

      class Downloader {
      def fileName;

      def download(address) {
      println "downloading from " + address
      fileName = address.tokenize("/")[-1]
      URL url = new URL(address);
      HttpURLConnection conn = url.openConnection();
      conn.setRequestProperty("Cookie", "gpw_e24=http%3A%2F%2Fwww.oracle.com%2F");
      conn.setAllowUserInteraction(false);
      //this won't handle re-directs from http to https we need to handle that ourselves
      conn.setInstanceFollowRedirects(true);
      conn.connect();
      processResponse(conn);
      }

      def processResponse(HttpURLConnection conn) {
      int status = conn.getResponseCode();
      println("Response Code = " + status);
      if (status == HttpURLConnection.HTTP_OK) {
      readInputStream(conn);
      } else {
      if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER) {
      handleRedirect(conn);
      }
      }
      }

      def handleRedirect(HttpURLConnection conn) {
      println "handling redirect"
      String newUrl = conn.getHeaderField("Location");
      println "new URL is " + newUrl;
      // open the new connnection again
      conn = (HttpURLConnection) new URL(newUrl).openConnection();
      conn.setRequestProperty("Cookie", "gpw_e24=http%3A%2F%2Fwww.oracle.com%2F");
      processResponse(conn);
      }

      def readInputStream(HttpURLConnection conn ) {
      def out = new BufferedOutputStream(new FileOutputStream(fileName));
      long fileSize = Long.parseLong(conn.getHeaderField("Content-Length"));
      InputStream is = conn.getInputStream();

      try {
      byte[] buffer = new byte[1024 * 10];
      int numRead = 0;
      long processedBytes = 0;
      while ((numRead = is.read(buffer)) != -1) {
      out.write(buffer, 0, numRead);
      processedBytes += numRead;
      println "processed ${processedBytes} bytes of ${fileSize}"
      }
      } finally {
      out.close()
      is.close();
      println "done"
      }
      }
      }

  • Avatar
    linda 2013-10-15T13:34:28

    thanks a lot, you made my day!

  • Avatar
    Lxur 2013-10-03T18:19:56

    Awesome

  • Avatar
    pessimism 2013-08-22T13:20:27

    Thank you!!!

  • Avatar
    kumaran 2013-08-14T08:48:09

    Is there any way to download the jre using a java program ???

    • Avatar
      Ivan Dyedov 2013-08-14T14:20:08

      yes, I'm assuming you can use the same trick for jre

  • Avatar
    Birju 2013-07-02T21:04:13

    Thanks a lot. This is the only post which helped

  • Avatar
    Jamalulkhair Khairedin 2013-06-29T09:50:51

    Great tips. Thanks

  • Avatar
    Bill 2013-06-23T01:22:44

    For 7u24 you also need --no-check-certificate

  • Avatar
    xxor 2013-05-21T12:45:18

    nice :)

  • Avatar
    Gabriela 2013-03-25T13:01:50

    Hello, I am trying to install the JDK for "winfows x86". After choosing my version, this site opens: "http://download.oracle.com/err..." (after accepting the license.) - I did not understand very well how to do to use that "cookie".

  • Avatar
    superjamie 2013-03-09T00:41:19

    I'm using this script to rename the file just to the filename, wget wget adds a big string on the end:

    if [ -n "$1" ]; then
    BASENAME=$(basename "$1")
    wget --no-cookies --header "Cookie: gpw_e24=http" -O $BASENAME $1
    fi

    If this page is not up to date, you can use tcpdump to watch for HTTP GETs then start a download from java.com yourself, you'll get the URL to feed to the script. Or you can just Google search for "/otn-pub/java/jdk/" in quotes, plus 7uXX or whatever update you're looking for, the URLs are usually out there and easily found.

  • Avatar
    ronanm 2013-02-04T02:56:16

    Saved me a major pain in the ass. Many thanks.

  • Avatar
    KDinesh 2013-02-02T12:56:44

    Thanks Bro, it was really helpful.

    Only problem I was facing ..my link contains ../otn/..which I replaced with ../otn-pub/.. and it is working fine.

  • Avatar
    Ben 2013-02-01T14:43:12

    Thanks for posting. Very satisfying to download the JDKs without going through Oracles silly hoops.

  • Avatar
    Steve Shockley 2013-01-30T19:35:19

    FYI, 7u11 is b21.

  • Avatar
    Janaka 2013-01-22T12:53:19

    Thanks,

  • Avatar
    Riaan 2013-01-16T18:48:15

    Hi,

    Any update on this? Doesn't seem to be working for me?

    • Avatar
      Ivan Dyedov 2013-01-16T20:46:44

      still works fine for me

  • Avatar
    sarvaan 2013-01-05T18:01:38

    can anyone pls let me know how to install jdk 6u38 in sun Solaris machine

    i need to install it as normal user in any of my location...

  • Avatar
    Clement 2012-11-29T20:21:41

    Gud and Nice. Helped a lot.

  • Avatar
    Wolfgang 2012-11-21T06:18:26

    I just found this page and successfully downloaded Oracle Java, just a second before realizing that I don't need Oracle Java at all. If Oracle doesn't want you to install their Java, you should use OpenJDK instead - it has packages for every decent Linux distribution... No hassle, it just works,...

    • Avatar
      pessimism 2013-08-22T13:19:55

      You are wrong. Android will not build with OpenJDK.

  • Avatar
    David 2012-11-15T17:59:14

    http://www.webupd8.org/2012/11...

    http://www.webupd8.org/2012/06...

    NOTE:

    The WebUpd8 Oracle Java repository doesn’t host any Java files, because that’s not allowed by the new Oracle Java license. Instead, the package uses a script which downloads and installs Oracle Java 6.

    As a reminder, the Oracle Java 7 PPA repository does not host any Java files but only an installer that automatically downloads and installs Oracle Java 7, like the flashplugin-installer package for instance.

  • Avatar
    Cameron 2012-11-15T04:26:32

    --no--cookies and http://www.oracle are unecessary. All that is needed is the presence of gpw_e24 cookie. This works:

    wget --header "Cookie: gpw_e24=a" http://...

  • Avatar
    Evans Yeh 2012-10-25T10:43:24

    Thank you, very useful

  • Avatar
    Taylor 2012-10-18T00:56:13

    I got a "scheme missing" error

    • Avatar
      Ivan Dyedov 2013-03-16T22:45:42

      make sure the URL you pass to wget is correct

  • Avatar
    Arven "Muckwaddle" Draconis 2012-10-15T07:39:02

    Thanks, this really helped a lot when administering a remote server which really doesn't have the bandwidth for using an X11 web browser. I otherwise would have had to download to my local system, and secure copy it to the server. And, given my current internet connection, would have been excruciatingly sloooow.

  • Avatar
    Chen Fliesher 2012-10-07T13:59:30

    Great work.
    If anyone looks for 7u5 it is build 05.

    /otn-pub/java/jdk/7u5-b05/jdk-7u5-linux-x64.rpm

  • Avatar
    Julian Melendez 2012-09-30T00:04:13

    Excelente ayuda My friend !!!!
    Muchas gracias !! u r da man @!@!

    saludos desde Tijuana

  • Avatar
    Giles Westwood 2012-09-25T18:29:21

    Hi Ivan,

    Thanks a lot for you work, saved me a lot time.

    I've written a script that tries various builds as they don't provide the build number on the site, this way you only have to work out the update version. Hopefully it's of use to others..

    #!/bin/bash
    #http://ivan-site.com/2012/05/download-oracle-java-jre-jdk-using-a-script/
    #visit http://www.oracle.com/technetwork/java/javase/downloads/index.html and determine latest update
    update=7
    version=7
    for bitness in x64 i586; do
    #Overwrite with the latest build
    for build in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20;do
    wget --no-cookies --header "Cookie: gpw_e24=http" "http://download.oracle.com/otn-pub/java/jdk/${version}u${update}-b${build}/jdk-${version}u${update}-linux-${bitness}.tar.gz"
    if [[ $bitness == 'i586' ]];then
    ourbitness="i386"
    else
    ourbitness="x86_64"
    fi
    mv jdk-${version}u${update}-linux-${bitness}.tar.gz jdk1.${version}.0_${update}-Linux-${ourbitness}
    done
    done
  • Avatar
    Darío 2012-09-25T06:19:53

    thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks

  • Avatar
    iantruslove 2012-09-21T20:45:10

    Nice, simple, and super-useful! Bookmarked.

  • Avatar
    hendra 2012-09-20T10:02:02

    Good job bro.., thanks alots

  • Avatar
    xkorey 2012-09-17T12:59:59

    good job!!!

  • Avatar
    calc 2012-08-23T18:45:20

    Thanks, you're my hero.

  • Avatar
    kirit 2012-08-06T11:57:16

    thank you

  • Avatar
    Hiren Patel 2012-08-05T14:07:46

    Brilliant worked like a charm, very useful indeed

  • Avatar
    Shmuel Krakower 2012-07-11T09:41:56

    Like! :)

  • Avatar
    Cristi 2012-05-18T18:12:24

    Thanks a lot. Very useful