Skip to content

Instantly share code, notes, and snippets.

@n0ts
Last active September 16, 2023 12:07
Show Gist options
  • Star 59 You must be signed in to star a gist
  • Fork 38 You must be signed in to fork a gist
  • Save n0ts/40dd9bd45578556f93e7 to your computer and use it in GitHub Desktop.
Save n0ts/40dd9bd45578556f93e7 to your computer and use it in GitHub Desktop.
Get latest Oracle JDK package bash shell script for linux/osx/windows
#!/bin/bash
# You must accept the Oracle JDK License Update
# https://www.oracle.com/java/technologies/javase-downloads.html
# usage: get_oracle_jdk_x64.sh <jdk_version> <platform> <ext>
# jdk_version: 14
# platform: linux or osx or windows
# ext: rpm or dmg or tar.gz or exec
jdk_version=${1:-14}
platform=${2:-linux}
ext=${3:-rpm}
readonly url="https://www.oracle.com"
readonly jdk_download_url1="$url/java/technologies/javase-downloads.html"
readonly jdk_download_url2=$(
curl -s $jdk_download_url1 | \
egrep -o "/\java\/technologies\/javase-jdk${jdk_version}-downloads.html"
)
[[ -z "$jdk_download_url2" ]] && echo "Could not get jdk download url - $jdk_download_url1" >> /dev/stderr
readonly jdk_download_url3="${url}${jdk_download_url2}"
readonly jdk_download_url4=$(
curl -s $jdk_download_url3 | \
egrep -o "download.oracle\.com\/otn-pub\/java\/jdk\/(${jdk_version})\..*\/.*\/jdk-${jdk_version}\..*[_]${platform}-x64_bin.${ext}\'" | tr -d \'
)
for dl_url in ${jdk_download_url4[@]}; do
wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
-N $dl_url
done
@jonathan-russo
Copy link

So this script has broken again on me. I have now decided to simply download the tar.gz files and put them on a local server for consistent access. Thanks for the original script @n0ts

@FRidh
Copy link

FRidh commented Dec 4, 2018

Seems to need https.

@alexws54tk
Copy link

JDK_DOWNLOAD_URL4 need https and change otn-pub to otn:

readonly jdk_download_url4=$(
    curl -s $jdk_download_url3 | \
    egrep -o "https\:\/\/download.oracle\.com\/otn\/java\/jdk\/[8-9](u[0-9]+|\+).*\/jdk-${jdk_version}.*(-|_)linux-(x64|x64_bin).$ext"
)

And now NEED oracle account login/passwd.

@umersajid59
Copy link

i soon i run the script I get this error "Could not get jdk download url - https://www.oracle.com/technetwork/java/javase/downloads/index.html"

@n0ts
Copy link
Author

n0ts commented Jun 1, 2020

i soon i run the script I get this error "Could not get jdk download url - https://www.oracle.com/technetwork/java/javase/downloads/index.html"

Hi, I updated get_oracle_jdk_x64.sh .

For Linux
./get_oracle_jdk_x64.sh 14 linux rpm

For macOS
./get_oracle_jdk_x64.sh 14 osx dmg

For Windows
./get_oracle_jdk_x64.sh 14 windows exe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment