The space station orbits above the Andes mountain range in Bolivia
The space station orbits above the Andes mountain range in Bolivia by NASA Johnson is licensed under CC-BY-NC-ND 2.0

🧼 How to Cleanly Remove Snap Java and Install OpenJDK via APT on Ubuntu

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.

Blue coffee grinders and espresso machine with cups in a chic cafe setting.
Photo by Niki on Pexels

Discover more from Kevin Marville Insights

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)