Explain Codes LogoExplain Codes Logo

Downloading Java JDK on Linux via wget is shown license page instead

java
prompt-engineering
best-practices
tools
Nikita BarsukovbyNikita Barsukov·Feb 6, 2025
TLDR

Fetch the Java JDK on Linux using this curl command:

curl -L -H "Cookie: oraclelicense=accept-securebackup-cookie" <JDK_DOWNLOAD_URL> -o jdk.tar.gz

Replace <JDK_DOWNLOAD_URL> with the exact link to the JDK you're after. This method deals with cookie acceptance needed by Oracle, and bypasses the license page. Please ensure you've agreed to Oracle's license terms beforehand.

Expanded explanation and tips

Utilizing wget for JDK retrieval

If you're a wget fan, here's what you need:

# Comment: Alright wget, don’t tell Oracle I told you this secret handshake… wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" <JDK_DOWNLOAD_URL>

Substitute <JDK_DOWNLOAD_URL> with the Oracle JDK download link in question. If your download gets interrupted, don't sweat, just use the -c option to continue the download:

# Comment: This is like time travel for downloads… wget -c --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" <JDK_DOWNLOAD_URL>

Keep in mind, for a 32-bit JDK, replace any occurrence of x64 in the download URL with i586.

After agreeing to Oracle's terms, start the download within 30 minutes. Why? Otherwise, you might find that your link has expired, forcing you to go through the steps again.

When browsers come to the rescue

Does wget or curl still remain stubborn? No problem. Start the download with a browser, hit pause, then copy the command from the downloads tab. This is an effective workaround for wget or curl to comply with Oracle's license.

Automating JDK deployment on Debian derivatives

In Debian or Ubuntu, use these commands to automate Java installation:

# Comment: Just sit back, relax, and let the automation do all the hard work… sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-installer

Just remember to check that the PPA and package names correspond to your JDK of choice. They're subject to changes.

Keep Oracle's rules under consideration

These approaches effectively bypass the license page, but Oracle's rules technically call for manual acceptance via a browser. I recommend using these CLI tricks responsibly, acknowledging the licensing agreements.

JDK 9 and beyond: Making life simpler

From JDK 9 onwards, downloading binaries isn't as messy. Portal like java.net simplify the task offering direct download links without the cookie tango:

# Comment: Now we're talking! Just me, wget, and JDK. And no cookie monster… wget [java.net-JDK-download-URL]

Make sure to replace [java.net-JDK-download-URL] with the desired URL from the website.

Up-to-date with evolving changes

Oracle JDK download URLs and cookie values can and do change - check the current requirement always to avoid stumbling blocks in downloads.