Ubuntu16自动安装Java8/Java9失败,download.oracle.com请求报404求助
Hey there! Let's dig into your problem and sort it out clearly:
Why your old setup suddenly stopped working
First off, this isn’t an intermittent network issue with download.oracle.com—the real reasons your automation broke are these key changes:
- WebUpd8 PPA is dead: The repository you tried to add (
webupd8) stopped maintaining their Java packages years ago. Their PPAs are no longer hosted, so any commands relying on them will fail now. - Ubuntu 16.04 is EOL: Ubuntu 16.04 reached its end-of-life in April 2021. The official archives and security repos are no longer active, which breaks package updates and installs for many tools, including Java.
- Oracle’s download restrictions: Oracle now requires a login to download older Java versions (like 8 and 9), so even direct calls to
download.oracle.comwould fail in automated scripts without handling authentication.
Is your original command flawed?
Absolutely—since the WebUpd8 PPA no longer exists, the line starting with echo "===> Add webupd8 repository..... points to a non-existent resource. That’s why it worked before but suddenly fails now.
One-click automated solutions
Since Ubuntu 16.04 is EOL, we’ll use either Ubuntu’s old-releases archive for OpenJDK 8 (more stable) or a trusted pre-built OpenJDK 9 binary (since 9 isn’t in the old repos).
Option 1: Install OpenJDK 8 (recommended for stability)
Save this as install-java8.sh, make it executable, and run it:
#!/bin/bash # Switch to Ubuntu's old-releases archive (since 16.04 is EOL) sudo sed -i 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list sudo sed -i 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list # Refresh package lists and install OpenJDK 8 sudo apt update -y sudo apt install -y openjdk-8-jdk # Verify installation echo "Java 8 installation complete:" java -version javac -version
Execute with:
chmod +x install-java8.sh && sudo ./install-java8.sh
Option 2: Install OpenJDK 9
OpenJDK 9 isn’t available in Ubuntu 16.04’s old repos, so we’ll download a pre-built binary from a trusted archive:
#!/bin/bash # Download OpenJDK 9 binary wget https://github.com/adoptium/temurin9-binaries/releases/download/jdk-9.0.4%2B11/OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz # Create JVM directory and extract the archive sudo mkdir -p /usr/lib/jvm sudo tar -xzf OpenJDK9U-jdk_x64_linux_hotspot_9.0.4_11.tar.gz -C /usr/lib/jvm/ # Set up environment variables echo "export JAVA_HOME=/usr/lib/jvm/jdk-9.0.4+11" >> ~/.bashrc echo "export PATH=\$JAVA_HOME/bin:\$PATH" >> ~/.bashrc source ~/.bashrc # Verify installation echo "Java 9 installation complete:" java -version javac -version
Execute with:
chmod +x install-java9.sh && sudo ./install-java9.sh
Quick notes
- Upgrade your system if possible: Ubuntu 16.04 has no security updates anymore. Moving to a supported release (like 20.04 or 22.04) will make package management far easier.
- Avoid OracleJDK for automation: Oracle’s login requirement makes automated downloads complicated. OpenJDK is fully compatible and free to use without restrictions.
内容的提问来源于stack exchange,提问作者Jitesh Sojitra

