How To Check Alternative Java Version In Linux

There might be a situation where you have installed multiple versions of Java on your Linux system and need to either switch between them or just view the installed versions. In this article, we will be discussing how to manage and check for alternative Java versions in Linux.

Checking Current Java Version

Before we learn how to check for alternative versions, let’s understand how we can view the current Java version running on your Linux system. To check the current version, you can use the following command in your terminal:

    java -version
    

This command will display the current running version of Java.

Checking for Alternative Java Versions

Now, let’s move on to the main topic of this article. To check for alternative Java versions, you can use the update-alternatives command provided by Linux. This command manages symbolic links for system commands and can be used to switch between different versions of the same command.

Here’s how you can use this command to check for alternative Java versions:

    update-alternatives --config java
    

Once you run this command, it will list the installed Java versions along with their paths. The currently active version will be indicated with a star (*).

Switching Between Java Versions

If you want to switch between Java versions, you can also do that using the update-alternatives command. When you run the command update-alternatives –config java, it will not only list the installed versions, but also prompt you to enter a number to select a version. Just enter the number corresponding to the version you want to use and hit enter. The system will update the default Java to the selected version.

Conclusion

Being able to check and switch Java versions on your Linux system gives you flexibility, especially if you’re working on different projects that require different Java versions. Using the update-alternatives command, you can easily manage your Java versions. It is a handy tool to have in your Linux command arsenal.