How to Change JAVA Version in Ubuntu: A Step-by-Step Guide

Salim Segaf Alqosam
2 min readJun 23, 2024

--

How to Change JAVA Version in Ubuntu: A Step-by-Step Guide

Hi Buddy! Are you having trouble setting the Java version? Yes, me to 🤣.

don’t worry, i have a solution! 💡

Java is a widely used programming language, and sometimes you may need to switch between different versions for compatibility reasons. Whether you are a developer working on multiple projects or a student learning Java, knowing how to manage Java versions on your Ubuntu system is essential. This guide will walk you through the process step by step.

okay let’s get straight to it.

Step-by-Step Solution

Step 1: Check Current JAVA Version

First, let’s see which version of Java is currently installed on your system. Open your terminal and run:

java -version

This command will display the current Java version. For example:

openjdk version "11.0.23" 2024-04-16
OpenJDK Runtime Environment (build 11.0.23+9-post-Ubuntu-1ubuntu120.04.2)
OpenJDK 64-Bit Server VM (build 11.0.23+9-post-Ubuntu-1ubuntu120.04.2, mixed mode, sharing)

Step 2: Install the Desired JAVA Version

You can install multiple versions of Java on your Ubuntu system. Let’s say you want to install Java 8 and Java 14. You can do this by running:

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

Step 3: Configure JAVA Version

After installing the required versions, you can configure which version to use by default. Using update-alternative Here’s how you can use it:

sudo update-alternatives --config java

This command will list all installed Java versions and prompt you to choose one. For example:

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-8-openjdk-amd64/bin/java 1081 manual mode
2 /usr/lib/jvm/java-14-openjdk-amd64/bin/java 1114 manual mode

Press <enter> to keep the current choice[*], or type selection number:

Enter the selection number of the Java version you wish to use *

Step 4: Verify the Changes

Finally, verify that the Java version has been updated:

java -version

Conclusion

Switching between different Java versions on Ubuntu is a straightforward process. With this guide, you can easily manage and configure the Java environment to suit your development needs. Happy coding!

If you found this guide helpful, don’t forget to give it a clap and share it with your fellow developers. For more such tutorials, follow my Medium blog!

--

--

Salim Segaf Alqosam
Salim Segaf Alqosam

Written by Salim Segaf Alqosam

Fullstack Developer | .NET | React.js | React Native

No responses yet