Java SDK
Linux
programming
installation
software location

Where can I find the Java SDK in Linux after installing it?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

On Linux, the Java SDK is usually not a single mysterious folder you have to guess. Its location depends on how Java was installed: from the distribution package manager, from a vendor tarball, or through a version manager. The reliable way to find it is to start from the active java or javac binary and resolve the real installation path.

Start From The Active Binary

The quickest way to discover the active Java installation is to ask the shell which executable is being used.

bash
which java
which javac

On many systems, these paths are symbolic links. To find the real target, resolve the link chain.

bash
readlink -f "$(which java)"
readlink -f "$(which javac)"

A typical result might look like this:

text
/usr/lib/jvm/java-17-openjdk-amd64/bin/java

Once you have that path, the SDK home is normally the parent directory above bin, such as /usr/lib/jvm/java-17-openjdk-amd64.

If javac exists, that is especially useful because it confirms you have a JDK and not only a JRE.

Common Installation Locations

Package-manager installations usually place Java under one of these directories:

  • '/usr/lib/jvm/'
  • '/usr/java/'
  • '/opt/ for some manual or vendor-managed installs'

Listing the JVM directory often shows all installed versions.

bash
ls -1 /usr/lib/jvm

On Debian or Ubuntu, OpenJDK packages commonly land in /usr/lib/jvm. On RHEL-derived systems, vendor layouts sometimes differ slightly, but the same approach of following java and javac still works.

If you installed a tarball manually, you may have extracted it into a custom location such as /opt/jdk-21 or your home directory. In that case, which java may only help if you already updated PATH.

Check JAVA_HOME Carefully

Many tools rely on JAVA_HOME, but it is only useful if it has been set correctly.

bash
echo "$JAVA_HOME"

If the variable is set, it should usually point to the SDK root directory, not to the bin/java executable itself.

A correct value looks like this:

bash
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH="$JAVA_HOME/bin:$PATH"

A common mistake is setting JAVA_HOME to something like /usr/lib/jvm/java-17-openjdk-amd64/bin/java. That is too specific and breaks tools that expect the SDK root.

Package Manager And Alternatives Tools

On systems that use the alternatives mechanism, you can inspect the configured Java providers directly.

bash
update-alternatives --display java
update-alternatives --display javac

Some distributions use the shorter command name alternatives instead.

bash
alternatives --display java

These commands help when multiple JDKs are installed and you need to know which one is currently active.

Package managers can also reveal installation details.

bash
dpkg -L openjdk-17-jdk | head
rpm -ql java-17-openjdk-devel | head

Use the one that matches your distribution family.

Verifying That It Is Really A JDK

The SDK, usually called the JDK, includes development tools such as javac, jar, and often javadoc. If you only see java but not javac, you may have a runtime-only installation.

bash
ls "$JAVA_HOME/bin" | rg '^(java|javac|jar|javadoc)$'

If javac is missing, install the development package rather than the runtime package.

Common Pitfalls

A common mistake is assuming /usr/bin/java is the SDK location. It is usually just a symlink managed by the package system or alternatives framework.

Another problem is confusing the JRE with the JDK. If you need to compile code, you must have javac, not only java.

Developers also often set JAVA_HOME to the executable path instead of the SDK root directory. Most build tools expect the root.

Finally, do not hard-code a path you found on one Linux distribution and assume it applies everywhere. Use which, readlink -f, and your package tools to confirm the actual installation on the current machine.

Summary

  • Start with which java or which javac to find the active executable.
  • Use readlink -f to resolve symlinks to the real installation path.
  • The SDK root is usually the parent directory above bin.
  • Common package-manager installs live under /usr/lib/jvm.
  • 'JAVA_HOME should point to the SDK root, not to bin/java.'
  • Check for javac to confirm you have a JDK rather than only a runtime.

Course illustration
Course illustration

All Rights Reserved.