
Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: March 18, 2024
Finding software’s installation directory is a very common operation. One common reason is for updating the PATH environment variable. For example, Java developers are often interested in finding the installation directory of Java.
In this tutorial, we’ll discuss the various ways to achieve this.
The update-java-alternatives tool is used to update all alternatives belonging to the Java runtime environment or development kit. We can use it along with the -l argument to find the location of the JDK or JRE:
$ update-java-alternatives -l
java-1.14.0-openjdk-amd64 1411 /usr/lib/jvm/java-1.14.0-openjdk-amd64
The update-alternatives command maintains symbolic links to determine the default commands. We can use it along with the –list argument to list the location of the Java SDK or its runtime:
$ update-alternatives --list java
/usr/lib/jvm/java-14-openjdk-amd64/bin/java
The which command shows the full path of a command and the readlink command resolves the symbolic link. We can use a combination of these commands to find the location of the JDK and JRE respectively:
$ readlink -f $(which javac)
/usr/lib/jvm/java-14-openjdk-amd64/bin/javac
$ readlink -f $(which java)
/usr/lib/jvm/java-14-openjdk-amd64/bin/java
In this case, the -f option follows every symbolic link in recursion fashion.
In this tutorial, we’ve discussed various ways to find the location of Java. We can use these commands in day-to-day life while working with the Linux system.