Blog

Change Multiple Java Version in Ubuntu

java-image
Java

Change Multiple Java Version in Ubuntu

While installing Jenkins latest version and I get the message that my Java version is causing problems in Ubuntu 22.04 version, so lets try to check the Java version and make sure that the suitable version, Let’s go to play around the Java package installation and switch the default between multiple version.

Just make sure that have you installed the Java package in your Ubuntu and Install it if not available or not installed.

java -version
Command 'java' not found, but can be installed with:
apt install default-jre              # version 2:1.11-72build2, or
apt install openjdk-11-jre-headless  # version 11.0.20+8-1ubuntu1~22.04
apt install openjdk-17-jre-headless  # version 17.0.8+7-1~22.04
apt install openjdk-18-jre-headless  # version 18.0.2+9-2~22.04
apt install openjdk-19-jre-headless  # version 19.0.2+7-0ubuntu3~22.04
apt install openjdk-8-jre-headless   # version 8u382-ga-1~22.04.1

Seems to be the above output, the ‘java’ not found. So, install the Java package using the command below,

apt install openjdk-18-jre-headless

Once you have installed the Java just check the version and can see the information of Java

java -version

openjdk version “18.0.2-ea” 2022-07-19
OpenJDK Runtime Environment (build 18.0.2-ea+9-Ubuntu-222.04)
OpenJDK 64-Bit Server VM (build 18.0.2-ea+9-Ubuntu-222.04, mixed mode, sharing)

Assume that, if you have installed multiple Java packages like 18.0.2 and 11.0.20. List out the installed the Java packages using the command below and change the default version,

update-java-alternatives --list

java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.18.0-openjdk-amd64 1811 /usr/lib/jvm/java-1.18.0-openjdk-amd64

Then, switch the java version to auto mode from 18 to 11 using the command below with a parameter.

sudo update-alternatives --config java

Now, checked the Java which has configured the default version,

java -version

openjdk version “11.0.20” 2023-07-18
OpenJDK Runtime Environment (build 11.0.20+8-post-Ubuntu-1ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.20+8-post-Ubuntu-1ubuntu122.04, mixed mode, sharing)

Spread the love

Leave your thought here

Your email address will not be published. Required fields are marked *