如何在Ubuntu系统中安装JDK 10?Oracle官方指引缺少系统配置说明
Hey there! I totally get it—Oracle's official docs for JDK 10 on Linux only cover downloading and extracting the archive, skipping the critical system configuration steps. Let me walk you through the complete process to get JDK 10 up and running properly on Ubuntu.
1. Download the JDK 10 Archive
Head over to Oracle's JDK archive (look for the Linux x64 .tar.gz package) and download it to your ~/Downloads directory (or wherever you prefer storing downloads).
2. Extract the Archive to a System Directory
Ubuntu typically stores Java installations in /usr/lib/jvm/, so we'll use that location:
- First, create the directory if it doesn't exist:
sudo mkdir -p /usr/lib/jvm/ - Extract the downloaded archive to this directory (replace
jdk-10*.tar.gzwith your actual filename if needed):
Pro tip: Runsudo tar -xvzf ~/Downloads/jdk-10*.tar.gz -C /usr/lib/jvm/ls /usr/lib/jvm/afterward to get the exact name of the extracted JDK folder (it'll look likejdk-10.0.2or similar—you'll need this for the next steps).
3. Configure Environment Variables (The Part Oracle Misses)
This step ensures your system recognizes JDK 10 globally. You have two options:
Option A: Global Configuration (All Users)
Edit the system-wide profile file:
sudo nano /etc/profile
Add these lines at the end of the file (replace jdk-10.x.x with your actual JDK folder name):
export JAVA_HOME=/usr/lib/jvm/jdk-10.x.x export PATH=$PATH:$JAVA_HOME/bin
Save and exit (press Ctrl+O, then Enter, then Ctrl+X). To apply the changes immediately:
source /etc/profile
Option B: User-Only Configuration (Current User)
If you only want JDK 10 available for your user account, edit your bashrc file instead:
nano ~/.bashrc
Add the same two lines as above at the end, then apply changes:
source ~/.bashrc
4. Set JDK 10 as the Default Java Version
If you have other Java versions installed, set JDK 10 as the default:
- Register JDK 10 with the alternatives system:
The numbersudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-10.x.x/bin/java 100 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-10.x.x/bin/javac 100100sets a high priority, so this version will be preferred over others. - Select the default Java and compiler versions:
When prompted, enter the number corresponding to JDK 10 and presssudo update-alternatives --config java sudo update-alternatives --config javacEnter.
5. Verify the Installation
To make sure everything worked, run these commands:
java -version javac -version
You should see output similar to this (version number may vary):
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment 18.3 (build 10.0.2+13)
OpenJDK 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
That's it—you've successfully installed and configured JDK 10 on Ubuntu!
内容的提问来源于stack exchange,提问作者Sam

