Java not found in “update-alternatives — config java” after installing java on linux
If you’ve recently installed Java on your Linux, but you’re still using previous Java version, you may need to change your Java version to get the benefits of the latest version. When you try to change the version of Java, you may not see the option for Java 18 in the terminal, even if you have already installed it. Don’t worry, in this article, i will show you how to change your Java version in linux, in my case im using parrot OS and change Java 17 to Java 18.
Checking Your Current Java Version
Before we start, let’s check which version of Java you’re currently using. Open your terminal and enter the following command:
java -version
Finding the Path of Java 18
As mentioned before, even if you have installed Java 18, you may not see the option to switch to it when using the update-alternatives --config java
command. This is because the system may not have registered Java 18 as an alternative. To fix this, we need to find the path of Java 18
Enter the following command in your terminal to find the path of Java 18:
ls /usr/lib/jvm/
This command will show you a list of installed Java versions on your system. Look for the folder with the name “java-18-openjdk-amd64” or something similar to that. Once you find it, copy the full path of that folder.
Registering Java 18 as an Alternative
Now that we have the path of Java 18, we need to register it as an alternative using the update-alternatives
command. Enter the following command in your terminal:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/<jdk-folder>/bin/java 1
This command registers Java 18 as an alternative with a priority of 1. If you have multiple Java versions installed on your system, you can set a higher priority for Java 18 by changing the number at the end of the command.
Switching to Java 18
Now that Java 18 is registered as an alternative, we can switch to it using the update-alternatives
command. Enter the following command in your terminal:
sudo update-alternatives --config java
This command will show you a list of Java versions installed on your system, including Java 18. Choose the number corresponding to Java 18 and press Enter.