Change default Java version in Ubuntu 22.04

This article is an extension to the Install OpenJDK JRE / JDK in Ubuntu 22.04. In this article, we discuss how to change default Java version in Ubuntu 22.04 release. As already discussed in previous article, we already have OpenJDK JDK v11 installed. And, here we install the v8 of OpenJDK Java Development Kit.

Note: Following operations would require you to have superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator.

For those who haven’t gone through the previous article, and are learning how it can be done. For them, we would install different versions of OpenJDK next.

Install OpenJDK Java Development Kit’s different versions

Firstly, update the repository. Hence, open a terminal and issue the following –

sudo apt update

To install OpenJDK JDK version 11 –

sudo apt install openjdk-11-jdk

To install OpenJDK JDK version 8 –

sudo apt install openjdk-8-jdk

Next, issue the command –

java -version

It would return with –

openjdk version "11.0.14" 2022-01-18
Change default Java version in Ubuntu 22.04

We would get the desired outcome using update-alternatives command-line utility –

sudo update-alternatives --config java

It will ask you to enter the selection number of the Java version. Choose the one which you prefer. And, press Enter.

If you earlier had v11 as default, and you preferred v8 this time. Then,

java -version

It would return with –

openjdk version "1.8.0_312"

In conclusion, we have discussed how to change default Java version in Ubuntu 22.04 release.