Default Java (JDK) on Ubuntu 18 Configuration

Here, I have written steps during changing default java from JDK version 11 to JDK version 8. All installed JDKs are located and can be found at: /usr/lib/jvm

Install new JDKs by running below command, in my case OpenJDK 8

sudo apt-get update
sudo apt-get install openjdk-8-jdk

Confirm current java version

java -version

All installed java version can be found by running below command

update-java-alternatives -l

Configure which java to use by default by running below

sudo update-alternatives --config java

Remove unnecessary JDK files if needed, in my case JDK 11

sudo apt-get remove openjdk-11-jdk
sudo apt-get autoremove
sudo rm -r /usr/lib/jvm/java-11-openjdk-amd64

Make sure default-java link points to expected JDK else change it manually.

cd /usr/lib/jvm
sudo ln -sfn java-1.8.0-openjdk-amd64 default-java

Again , confirm current java version changes

java -version

Output will be something like below

openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~18.04-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

Optional (advanced): See all program links related to java

update-alternatives --get-selections | grep java

Have something to say? Leave a comment!