Update Alternatives: Changing Java version on Ubuntu

Update Alternatives: Changing Java version on Ubuntu

Last updated:
Table of Contents

List all versions

use sudo update-alternatives --list java

Example: Java 8 (OpenJDK) and Java 11 (also OpenJDK) are available

$ sudo update-alternatives --list java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

Change version

Use sudo update-alternatives --config java and choose the number you wish to use

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
* 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode