How to Install or Update Java JDK on Ubuntu in 2025
If you want to develop Java applications on Ubuntu, you need to install the Java Development Kit (JDK). Nowadays, the most common choice is OpenJDK, which is open-source and maintained by the community.
This guide covers the easiest and safest way to install or update Java JDK on Ubuntu systems in 2025, including Ubuntu 16.04, 20.04, 22.04, and later.
1. Check if Java is already installed
Open a terminal and run:
java -version
If you see something like:
openjdk version "17.0.x" 2024-xx-xx
OpenJDK Runtime Environment ...
OpenJDK 64-Bit Server VM ...
You have Java installed. If it's outdated or missing, continue below.
2. Update your package lists
Always update your package lists before installing:
sudo apt update
3. Install OpenJDK (latest supported LTS version)
As of 2025, the recommended long-term support (LTS) version is OpenJDK 17 or OpenJDK 20 (latest stable). To install OpenJDK 17, run:
sudo apt install openjdk-17-jdk
Or if you want the absolute latest stable JDK (e.g., OpenJDK 20):
sudo apt install openjdk-20-jdk
4. Verify the installation
Check the installed Java version again:
java -version
You should see the new version info, for example:
openjdk version "17.0.x" 2024-xx-xx
OpenJDK Runtime Environment ...
OpenJDK 64-Bit Server VM ...
Also, check the compiler:
javac -version
5. Manage multiple Java versions (optional)
If you have multiple Java versions installed, you can configure the default one with:
sudo update-alternatives --config java
And for the compiler:
sudo update-alternatives --config javac
Select the number corresponding to the version you want as default.
6. Set JAVA_HOME environment variable (optional but recommended)
Add this to your shell profile (e.g., ~/.bashrc
or /etc/environment
):
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$JAVA_HOME/bin:$PATH
Then reload your profile:
source ~/.bashrc
Check JAVA_HOME
:
echo $JAVA_HOME
Bonus: Installing Oracle JDK in 2025
Oracle JDK is now under a paid license for commercial use. If you want Oracle JDK, download it manually from Oracle's website and install it manually or use third-party scripts (not recommended for most users). OpenJDK is fully compatible and free.
Summary
- Use
sudo apt install openjdk-17-jdk
or newer for the easiest, up-to-date Java installation on Ubuntu. - Manage multiple versions with
update-alternatives
. - Set
JAVA_HOME
if needed. - Avoid manual installation of Oracle JDK unless strictly required.
Happy coding! 👨💻👩💻