Java Uninstall – How to Remove Versions of OpenJDK

javaopenjdkuninstall

I am using Linux Mint XFCE 20.

Recently I installed Java by running sudo apt-get install openjdk and it automatically installed versions 8 and 11 of both JRE and JDK, including JRE headless.

It turns out that I needed only openjdk 16 to run what I wanted to, and having other versions of java are kinda pointless. My main issue is that programs default to version 8 and I can't seem to fix it.

So how can I uninstall both versions 11 and 8 and just keep 16?

Best Answer

The unwanted versions can be removed by name:

sudo apt remove openjdk-8-jdk
sudo apt remove openjdk-11-jdk

They are installed with different packages.

You can see all the openjdk packages available with this command:

sudo apt update
apt-cache search openjdk

You can see all openjdk packages in your system with:

dpkg -l | grep openjdk

Note: I am a RedHat user, not a Mint expert but this is pretty much the same on every distro. I just checked the package names on Mint for those commands to work.

Related Question