Switching from Snap to APT for Java is a smart move for developers who want stability, better toolchain compatibility, and easier configuration. Keep your setup lean and professional by relying on the APT-managed OpenJDK. My gist path file : https://gist.github.com/Kvnbbg/735c4b35f8400e3b93c48104984938e3
We skipped adding JAVA_HOME
in this guide for simplicity. But if you need to set it later (e.g., for Android SDK or Maven), feel free to ask or check out below:
👉 How to Set JAVA_HOME on Ubuntu :
# Step 1: Remove Snap version cleanly (if installed)
sudo snap remove openjdk
# Step 2: Clean any leftover APT attempts or broken packages (if any)
sudo apt autoremove --purge -y
sudo apt clean
# Step 3: Update package list
sudo apt update
# Step 4: Install the latest LTS OpenJDK from Ubuntu's repos
sudo apt install openjdk-21-jdk -y
# Step 5: Verify installation
java -version
javac -version
# Step 6 (Optional but recommended): Set JAVA_HOME permanently
echo 'export JAVA_HOME="/usr/lib/jvm/java-21-openjdk-amd64"' >> ~/.bashrc
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
🎯 Result
You now have:
- A clean Java installation with no Snap interference
- System-wide compatibility with development tools like Eclipse, IntelliJ, Maven, Gradle, and Android Studio
- A reliable OpenJDK version maintained via Ubuntu’s APT system
📌 Why Remove Snap Java?
While Snap packages are convenient, they sometimes create issues with:
- File paths not being standard (
/snap/...
) - JAVA_HOME configuration problems
- Confined environments that limit system integration
- Compatibility issues with IDEs like Eclipse or IntelliJ
To avoid all this, using the official APT method is cleaner and more predictable—especially for developers.

Discover more from Kevin Marville Insights
Subscribe to get the latest posts sent to your email.