EN
Ubuntu 20.04 / Debian - switch default java version
8 points
In this short article, we would like to show how to switch the default Java version into a different one under Ubuntu 20.04 / Debian linux.
Quick solution (run the following command to open configuration):
xxxxxxxxxx
1
sudo update-alternatives --config java
Note: command will list and ask us to select an active Java version.
The example shows switching from Java 14 to Java 8.
xxxxxxxxxx
1
$ java -version
2
openjdk version "14.0.2" 2020-07-14
3
OpenJDK Runtime Environment (build 14.0.2+12-Ubuntu-120.04)
4
OpenJDK 64-Bit Server VM (build 14.0.2+12-Ubuntu-120.04, mixed mode, sharing)
5
6
john@john-pc:~$ sudo update-alternatives --config java
7
There are 2 choices for the alternative java (providing /usr/bin/java).
8
9
Selection Path Priority Status
10
------------------------------------------------------------
11
0 /usr/lib/jvm/java-14-openjdk-amd64/bin/java 1411 auto mode
12
* 1 /usr/lib/jvm/java-14-openjdk-amd64/bin/java 1411 manual mode
13
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
14
15
Press <enter> to keep the current choice[*], or type selection number: 2
16
17
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
18
19
john@john-pc:~$ java -version
20
openjdk version "1.8.0_275"
21
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~20.04-b01)
22
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)
23
24
john@john-pc:~$