Java

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

19 September 2026 · 8 min read

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

So, you’ve just installed the Java SDK on your Linux machine, and you’re eager to start developing amazing Java applications. But, a common hurdle many developers face, especially those new to Linux or Java, is figuring out where to find the Java SDK in Linux after installing it. The Java Development Kit (JDK) is the cornerstone for building and running Java applications, containing essential tools like the Java compiler (javac), Java Runtime Environment (JRE), and various libraries. Locating the JDK installation directory is crucial for configuring environment variables like JAVA_HOME, which many Java-based tools and IDEs rely on. Understanding this process empowers you to effectively manage your Java development environment and avoid frustrating setup issues. This guide will walk you through the common locations and methods to pinpoint your Java SDK installation, making your development journey smoother and more productive.

Common Installation Locations for the Java SDK on Linux

The location of the Java SDK after installation on Linux can vary depending on the distribution you’re using and the method you chose for installation. One of the most common places to look is under the /usr/lib/jvm directory. This directory is often used by package managers like apt (Debian, Ubuntu) and yum (CentOS, Fedora) to store multiple Java installations. When you install the JDK using a package manager, it typically creates a subdirectory within /usr/lib/jvm named after the Java version and vendor, such as java-11-openjdk-amd64.

Another possible location is /opt/. This directory is generally used for installing software manually, often from downloaded archives. If you downloaded the JDK as a .tar.gz file from the Oracle website or another source and extracted it yourself, you likely placed it in /opt/. For example, you might find a directory like /opt/jdk-17.0.2 containing the JDK files. Remembering how you installed the Java SDK is paramount to finding it.

Lastly, it’s also possible, though less common for system-wide installations, that the JDK resides within your home directory, particularly if you’re setting up a Java environment for a specific project and want to isolate it. In this scenario, it might be in a directory like ~/java/jdk-1.8.0_301. Always check these standard locations when searching for the Java SDK after installation. According to Oracle documentation, using a package manager is the preferred method for most users, as it simplifies updates and dependency management [Oracle JDK Downloads].

Methods to Locate the Java SDK Path

Even if you’re unsure where the Java SDK was installed, several methods can help you pinpoint its location. The which java command is a good starting point. This command searches your PATH environment variable for the java executable, which is part of the JRE (Java Runtime Environment) bundled with the JDK. However, which java only gives you the location of the JRE’s java executable, not the entire JDK installation directory.

To find the actual JDK path, you can use the update-alternatives command (on Debian-based systems like Ubuntu). Run sudo update-alternatives –config java. This will display a list of available Java installations, allowing you to select the one you want to use as the default. The output will show the full path to each Java installation, which you can then note down. This command is extremely helpful for managing multiple Java versions installed on your system.

Alternatively, you can use the javac -version command. While primarily used to check the Java compiler version, this command also implicitly relies on the JAVA_HOME environment variable or the system’s default Java installation. If javac is working correctly, it means your system knows where the JDK is located. You can then use commands like whereis javac or which javac to find the compiler’s location and then deduce the JDK’s root directory from there. Often, the javac executable is located in the bin directory within the JDK installation folder. The echo $JAVA_HOME command will also work if the JAVA_HOME variable has been properly set.

Setting the JAVA_HOME Environment Variable

Once you’ve located the Java SDK installation directory, setting the JAVA_HOME environment variable is crucial for many Java-based tools and applications. This variable tells these tools where to find the JDK. Setting JAVA_HOME incorrectly can lead to build failures or runtime errors, making it an essential step in configuring your Java development environment. Many IDEs, such as IntelliJ IDEA and Eclipse, rely on JAVA_HOME to properly configure the Java project.

To set JAVA_HOME permanently, you need to modify your shell’s configuration file, such as .bashrc or .zshrc (depending on the shell you’re using). Open the file with a text editor (e.g., nano ~/.bashrc) and add the following line, replacing /path/to/your/jdk with the actual path to your JDK:

export JAVA_HOME=/path/to/your/jdk

After adding this line, save the file and source it to apply the changes to your current shell session: source ~/.bashrc or source ~/.zshrc. You can then verify that JAVA_HOME is set correctly by running echo $JAVA_HOME. This command should output the path you just set. Remember to always double-check the path to the JDK to avoid any errors. According to a Stack Overflow survey, misconfigured environment variables are a common source of issues for Java developers, highlighting the importance of accurate setup [Stack Overflow Blog - Debugging Tips].

To add the Java bin directory to your PATH environment variable, add this line to your .bashrc or .zshrc file:

export PATH=$PATH:$JAVA_HOME/bin

This ensures that you can run Java commands like java and javac from any directory.

Troubleshooting Common Issues

Even after following the steps above, you might encounter some common issues. One frequent problem is “command not found” errors when trying to run Java commands. This usually indicates that the bin directory of your Java SDK is not in your PATH environment variable. Ensure that you’ve correctly added $JAVA_HOME/bin to your PATH in your shell configuration file and sourced the file.

Another issue is the wrong Java version being used. This can happen if you have multiple Java installations and the JAVA_HOME variable is pointing to the wrong one. Double-check the JAVA_HOME setting and make sure it points to the desired JDK version. Also, use the java -version and javac -version commands to verify the versions being used by the system. If the versions are inconsistent, it means that the JAVA_HOME variable or the system’s default Java installation is not configured correctly.

Sometimes, even after setting JAVA_HOME, your IDE might not recognize it. In this case, you may need to explicitly configure the JDK path within the IDE’s settings. Each IDE has its own way of configuring the JDK, so refer to the IDE’s documentation for specific instructions. Remember to restart the IDE after making any changes to the JDK settings. By carefully following these troubleshooting steps, you can resolve most common issues related to finding and configuring the Java SDK on Linux.

Infographic here
- Check /usr/lib/jvm first for package manager installations. - Verify JAVA\_HOME after locating the JDK.
  1. Use which java to find the JRE path.
  2. Use update-alternatives –config java for JDK path (Debian-based).
  3. Set JAVA_HOME in .bashrc or .zshrc.
  • “Command not found” errors: Check your PATH.
  • Wrong Java version: Verify JAVA_HOME and system defaults.

Featured Snippet: To accurately locate your Java SDK installation path on Linux, start by examining the /usr/lib/jvm directory if you used a package manager like apt or yum. If you manually installed from a .tar.gz file, check the /opt/ directory. You can also use the update-alternatives –config java command on Debian-based systems to see a list of available Java installations. Finally, remember to set your JAVA_HOME environment variable to point to the correct JDK path for your development tools and applications to function correctly.

FAQ ---
Where is the Java SDK installed on Ubuntu?
On Ubuntu, the Java SDK is typically installed in the /usr/lib/jvm directory if you used apt. You can also find it in /opt if you installed it manually.
How do I set the JAVA\_HOME environment variable?
Edit your .bashrc or .zshrc file and add the line export JAVA\_HOME=/path/to/your/jdk, replacing /path/to/your/jdk with the actual path to your JDK. Then, run source ~/.bashrc or source ~/.zshrc to apply the changes.
What if I have multiple Java versions installed?
Use sudo update-alternatives --config java to select the default Java version on Debian-based systems. Make sure your JAVA\_HOME variable points to the correct version.
Finding the Java SDK on Linux after installation might seem daunting at first, but with the right knowledge and tools, it becomes a straightforward process. We've covered common installation locations, methods for pinpointing the path, setting the JAVA\_HOME environment variable, and troubleshooting common issues. Remember that careful configuration of your Java environment is crucial for a smooth development experience.

Now that you know how to locate and configure your Java SDK, it’s time to put that knowledge into practice. Start building your Java applications, explore new libraries, and contribute to the vibrant Java community. Don’t let environment setup be a barrier to your coding journey! Explore other helpful topics such as “Best Java IDEs for Linux” or “Troubleshooting Common Java Errors” to further enhance your development skills. Happy coding! For further reading, consider checking out Red Hat’s documentation on installing Java [Red Hat - Installing Java].

Question & Answer :
I installed JDK using apt-get install but I don’t know where my jdk folder is. I need to set the path for that. Does any one have a clue on the location?

This depends a bit from your package system … if the java command works, you can type readlink -f $(which java) to find the location of the java command. On the OpenSUSE system I’m on now it returns /usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/bin/java (but this is not a system which uses apt-get).


On Ubuntu, it looks like it is in /usr/lib/jvm/java-6-openjdk/ for OpenJDK, and in some other subdirectory of /usr/lib/jvm/ for Suns JDK (and other implementations as well, I think).

Debian is the same.


For any given package you can determine what files it installs and where it installs them by querying dpkg. For example for the package ‘openjdk-6-jdk’: dpkg -L openjdk-6-jdk