Authors Top

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

1. Overview

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.

2. Using the update-java-alternatives Command

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

3. Using the update-alternatives Command

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

4. Using the which and readlink Commands

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.

5. Conclusion

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.

Authors Bottom

If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.

Comments are closed on this article!