Java is a versatile programming language and platform that allows you to run applications and software on various devices and operating systems. In Linux systems like Ubuntu, Debian, and Fedora, there are different versions and implementations of Java available, such as OpenJDK, Oracle JDK, and AdoptOpenJDK. Depending on your preferences and needs, you may want to switch between these Java alternatives.
To change the Java alternative on your Linux system, you can use the update-alternatives tool. This utility manages symbolic links that point to different versions or implementations of a program, such as Java. By using the update-alternatives tool, you can list, install, remove, or configure the Java alternatives on your Linux system.
Follow these steps to change the Java alternative on your Linux system using the update-alternatives tool:
Open a terminal window and type the following command to list the available Java alternatives on your system:
sudo update-alternatives –config java
This will display a table with the following information:
Selection: The number that corresponds to each alternative.
Priority: The priority level that determines the default alternative.
Status: The status of each alternative, such as auto or manual.
Path: The path of each alternative.
To change the Java alternative, enter the number of the alternative you want to use and press Enter. For example, if you want to use OpenJDK 11 as your Java alternative, enter 2 and press Enter.
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-17-oracle/bin/java 1091 auto mode
1 /usr/lib/jvm/java-16-oracle/bin/java 1090 manual mode
* 2 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
To verify that the Java alternative has been changed, type the following command to check the version of Java in use:
This will display the version information of the selected Java alternative. For example, if you have chosen OpenJDK 11, you will see something like this:
openjdk version “11.0.12” 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Ubuntu-0ubuntu1.20.04, mixed mode)
Changing the Java alternative on your Linux system allows you to use different versions or implementations of Java based on your preferences and requirements. By utilizing the update-alternatives tool, you can easily manage and optimize your Java environment and performance on Linux.