Ubuntu机器安装Oracle Java 8失败,请求技术帮助
Hey there, I’ve dealt with this exact problem before—Oracle tightened up their download policies a while back, which breaks the automated oracle-jdk8-installer package since it can’t handle the required login and license agreement. Let’s get this sorted out:
Option 1: Manually Cache the Required JDK Package
This lets the installer use your pre-downloaded file instead of trying to fetch it from Oracle’s servers:
- First, clean up any partial or failed installation remnants:
sudo apt-get purge oracle-jdk8-installer sudo apt-get autoremove && sudo apt-get clean - Go to Oracle’s official JDK 8 archive page, accept the license agreement, and download the 64-bit Linux tar.gz file matching the version your installer was targeting—for your case, that’s
jdk-8u161-linux-x64.tar.gz. - Copy the downloaded file to the installer’s cache directory:
sudo cp ~/Downloads/jdk-8u161-linux-x64.tar.gz /var/cache/oracle-jdk8-installer/ - Re-run the installation command:
sudo apt-get install oracle-jdk8-installer
The installer will now pick up the cached file instead of attempting to download it, bypassing the authentication block that was causing the issue.
Option 2: Switch to OpenJDK 8 (Recommended)
Oracle JDK 8 has restricted public downloads now, so OpenJDK 8 is a fully functional, open-source alternative that’s far easier to install and maintain:
- Install OpenJDK 8 and its development kit:
sudo apt-get install openjdk-8-jdk - If you have multiple Java versions installed, set OpenJDK 8 as your default:
sudo update-alternatives --config java sudo update-alternatives --config javac
Just select the OpenJDK 8 option from the menu that appears.
Why the Original Command Failed
Oracle now requires users to log in and accept their license agreement to download older JDK versions like 8u161. The oracle-jdk8-installer package wasn’t updated to handle this authentication step, so it gets stuck mid-download when trying to access the file without proper credentials.
内容的提问来源于stack exchange,提问作者Nipun

