How to tell if JRE or JDK is installed
Instant JRE/JDK check: run java -version
and javac -version
in your terminal or command prompt. Seeing version data means you're good to go; no output or errors denote they're either missing or not added to the system path.
java -version
javac -version
Further validation involves examining the environment setup, determining the specific directories, and confirming the availability of the necessary tools for Java development and execution.
Setting up and verifying your Java environment
Configuring your environment
Initially, double-check that your Java path is correctly established in the system environment variables. This path helps your system know where to look for executable files like java
and javac
.
Checking PATH and JAVA_HOME
For troubleshooting, check what JAVA_HOME
is set to using echo $JAVA_HOME
on Unix systems or echo %JAVA_HOME%
on Windows. Likewise, check if the Java bin
directory is included in your system’s PATH via echo $PATH
or echo %PATH%
. If not properly set, these could lead to errors despite the actual Java installation.
echo $JAVA_HOME // "home" of Java, or where it showers and sleeps
echo $PATH // reveals where Java has "permission" to loiter
Finding Java on Unix-based systems
On Unix systems (like Linux or macOS), the which java
or command -v java
commands reveal the location of the java
binary on your system’s execution path. The returned path specifies where java
resides—if it's on the PATH.
which java
command -v java
To examine the entire system for Java installations, including those not on the PATH, use find / -name "java"
. This command may take a while to complete.
find / -name "java" // "where in the world is Java San Diego?"
Determining Java presence for Mac users
For Mac enthusiasts, the /Library/Java/JavaVirtualMachines/
directory stores your JDK installations. If installed, you'll spot a directory for each version. Ensure to set JAVA_HOME
to the path of the version you plan on using.
Checking for JDK, not just JRE
Be mindful that the presence of java
in your Unix-based PATH does not guarantee a full JDK. Look specifically for the javac
executable. The existence of javac
promises JDK, and not just JRE.
javac -version // "javac, do you exist?"
Verifying JDK on Windows
For Windows users, navigate to the bin
directory (generally found in C:\Program Files\Java\jdk<version>\bin
). Execute javac -version
here to confirm JDK presence.
cd /d C:\Program Files\Java\jdk<version>\bin // "show me the way to go home (to the bin)"
javac -version // "javac, are you in there?"
A warning to Linux users
A note to Linux comrades: many Linux distributions' Java executables are part of the OpenJDK JRE. So, appearances can be deceiving, and do not take openjdk
in your which java
or command -v java
output as a JDK confirmation.
Anticipating and tackling potential issues
Different versions of JDK and JRE
Be aware that your java -version
and javac -version
should report the same version number. Mismatches could lead to unexpected compilation/execution issues.
Missing JRE?
If you're using JDK version 11 or newer, don't be alarmed if there isn't a separate JRE. The JDK now includes all the capabilities required for JRE.
Check your version
For development, using the JDK is generally necessary, but ensure you have the right version for your projects. Java continues to evolve, and newer versions may introduce breakages in backward compatibility, or you may require features not present in older versions.
Setting environment variables in macOS and Linux
On macOS and Linux, experiencing an error when setting JAVA_HOME or updating to a new JDK usually means you need to do a little extra work. Open up your shell's profile script and modify the JAVA_HOME
variable to the correct paths, then use source ~/.bash_profile
(or equivalent) to apply your changes. This tweak is the range of motion exercise for your system's Java muscles.
Was this article helpful?