Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

“Java desktop path” usually means configuring your operating system so terminals and development tools can find a Java Development Kit (JDK). Set JAVA_HOME to the JDK’s root directory and add its bin folder to PATH. You need a JDK—not just a runtime—if you want to compile code with javac. The steps below cover Windows, macOS, and Linux, then show how to verify which Java installation is actually in use.

Understand JDK, JAVA_HOME, PATH, and CLASSPATH

Term What it does Example
JDK The Java Development Kit, including development tools such as the compiler. C:Program FilesJavajdk-25
JAVA_HOME A variable that identifies the JDK installation’s root directory. C:Program FilesJavajdk-25
PATH A list of directories the operating system searches for commands such as java and javac. %JAVA_HOME%bin on Windows
CLASSPATH A setting that can tell Java where to find classes and libraries. Usually leave it unset for modern projects.
java / javac The Java launcher / Java compiler. Both are normally in the JDK’s bin folder.

The key distinction: JAVA_HOME points to the JDK root, while PATH points to executable directories. Do not set JAVA_HOME to the bin folder. Adding JAVA_HOME alone also does not make the java command available; the JDK’s bin directory must be on PATH. Conversely, the shell can find Java through PATH while a build tool fails because JAVA_HOME is missing or wrong. Oracle documents the separate roles of PATH and CLASSPATH in its environment paths guide.

Install the right JDK first

If you only need to run an application, its compatible runtime may be enough; some modern applications bundle one. If you are writing or compiling Java, install a JDK. A JDK is also normally needed by Maven, Gradle, Android Studio, and many IDE workflows. See Oracle’s JDK installation overview for supported installation approaches.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the Java major version your course, project, or employer requires. If none is specified, an LTS release is generally the safer default for learning and longer-lived projects; a feature release can be appropriate when you need its newer capabilities. As of August 2026, Oracle identifies JDK 26 as its latest feature release and JDK 25 as its latest LTS release. That status changes, so check the current Java downloads page rather than treating an example version here as permanent.

Java is available from multiple vendors, including Oracle, Eclipse Temurin, Microsoft, Amazon Corretto, Azul Zulu, BellSoft Liberica, and IBM Semeru. The language is not limited to one vendor, but distributions can differ in packaging, support lifecycle, update policy, licensing, and platform coverage. Choose a supported build matching your project’s Java version and your operating system and processor architecture (for example, Windows x64 versus ARM64, or Intel versus Apple silicon). Check your organization’s license and support requirements where applicable; a vendor’s licensing terms are not interchangeable. The OpenJDK project and the SDKMAN! JDK catalog are useful starting points for understanding the ecosystem.

Set Java PATH on Windows

Use the graphical method for a persistent setup. The example below uses JDK 25 only to illustrate the folder format—select your actual installed directory and version.

  1. Install a JDK. An installer may use a directory such as C:Program FilesJavajdk-25, but the exact location depends on the vendor, installer, and choices you made.
  2. Open Start, search for Environment Variables, and select Edit the system environment variables.
  3. In the System Properties window, select Environment Variables.
  4. Under User variables for your account, select New. For an individual development machine, user-level variables are usually preferable because they do not affect other accounts or require administrator privileges. Use system variables only when all users or a managed setup needs them.
  5. Create JAVA_HOME with the value set to your JDK root, for example C:Program FilesJavajdk-25. Do not add bin.
  6. Under the same variables section, select Path, choose Edit, and add a new entry: %JAVA_HOME%bin. Add an entry rather than replacing the existing path.
  7. Confirm the dialogs. Close open terminals, then start a new Command Prompt or PowerShell window.

Microsoft’s Windows Java development guide also describes setting JAVA_HOME to the JDK folder and adding %JAVA_HOME%bin to Path. Oracle notes that its Windows installer commonly uses a C:Program FilesJavajdk-<FEATURE> pattern, and documents a possible javapath conflict in its Windows installation guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Temporary Windows setup

To test without changing persistent settings, run these commands in Command Prompt, substituting the JDK’s real path:

set JAVA_HOME=C:Program FilesJavajdk-25
set PATH=%JAVA_HOME%bin;%PATH%

PowerShell equivalent:

$env:JAVA_HOME = 'C:Program FilesJavajdk-25'
$env:Path = "$env:JAVA_HOMEbin;$env:Path"

These changes apply only to that terminal session and programs launched from it. They disappear when the window closes.

Set Java PATH on macOS

Use macOS’s JDK discovery utility instead of guessing a vendor-specific installation path. To list installed JDKs, run:

/usr/libexec/java_home -V

For the current shell session, select the default discovered JDK and put its tools first on PATH:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH="$JAVA_HOME/bin:$PATH"

To choose a specific installed major version, such as 25, use:

export JAVA_HOME=$(/usr/libexec/java_home -v 25)
export PATH="$JAVA_HOME/bin:$PATH"

The requested version must already be installed. To make the setting persistent for the common zsh setup, add the appropriate two export lines to ~/.zshrc, replacing 25 if your project needs another version. Then reload it:

source ~/.zshrc

macOS commonly uses zsh, but another shell or an application launched from the desktop may not read ~/.zshrc. The environment inherited by an IDE depends on how it is launched. Oracle’s JDK installation guide documents macOS installation and the java_home mechanism.

Set Java PATH on Linux

With a JDK installed from a distribution package manager, first check whether the distribution’s alternatives mechanism already selects the desired Java. Package names and repositories vary by Linux distribution and release, so there is no single installation command that applies everywhere.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On Debian- or Ubuntu-style systems where these tools are available, list registered Java installations and choose the desired commands with:

update-java-alternatives --list
sudo update-alternatives --config java
sudo update-alternatives --config javac

A JDK extracted manually may not be registered with alternatives. For example, if it is located at /opt/jdk-25, configure the current shell with:

export JAVA_HOME=/opt/jdk-25
export PATH="$JAVA_HOME/bin:$PATH"

For a per-user persistent setting, put those lines in the startup file used by your shell—often ~/.bashrc for interactive Bash or ~/.zshrc for zsh—then reload the file. Some distributions and login shells use ~/.profile or another startup file instead. A setting in one shell’s file may not apply to a different shell, a graphical IDE, or a service. For a system-wide change, use your distribution’s documented configuration and understand that it affects other users and applications.

Oracle’s installation overview covers Linux package and archive approaches. If you use a manually extracted JDK, set its actual root path; do not assume it has been added to alternatives automatically.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify the selected Java installation

Open a new terminal after persistent changes. Check both versions and executable locations: the version command tells you what runs, while the location command reveals which file is found first.

Shell Commands
Windows Command Prompt echo %JAVA_HOME%
java -version
javac -version
where java
where javac
Windows PowerShell $env:JAVA_HOME
java -version
javac -version
Get-Command java
Get-Command javac
macOS or Linux echo "$JAVA_HOME"
java -version
javac -version
command -v java
command -v javac

java -version reports the Java launcher found through command lookup; it does not prove that JAVA_HOME points to the same JDK. Check both. On Linux, where supported, resolve a symlink to inspect the selected executable’s destination:

readlink -f "$(command -v java)"

A successful development setup normally lets both java -version and javac -version run and shows paths belonging to the intended JDK.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fix common Java path problems

Symptom Likely cause What to do
java is not recognized or java: command not found The JDK’s bin directory is absent from the effective PATH, or the terminal predates the change. Confirm the JDK path, add its bin directory to PATH, then open a new terminal.
javac is not recognized Only a runtime is installed, or the shell finds a different installation. Install a JDK and check where javac, Get-Command javac, or command -v javac.
JAVA_HOME is not defined correctly It points to bin, a nonexistent location, or a runtime without the expected development tools. Set it to the existing JDK root—the parent directory of bin.
The terminal reports an older Java version An older executable appears earlier in PATH, or a shell startup file or alternatives setting overrides the intended version. Inspect all reported locations and reorder or remove stale entries; select the intended alternative if applicable.
The shell works but Maven or Gradle fails The build tool may read a different JAVA_HOME, use a toolchain, or run under an IDE-specific JDK. Inspect the tool’s Java runtime and configure the required JDK in the build or IDE settings.
Java works in the IDE but not the terminal The IDE has its own configured runtime or project JDK. Configure the system shell separately and verify it with command and location checks.
A change has no effect The terminal or application was already open and inherited the old environment. Close and reopen it. For IDEs, restart the IDE after changing persistent variables.

Windows: the wrong executable wins

Windows searches path entries in order. If an old Java directory appears before %JAVA_HOME%bin, it can supply the command even though the new JDK is installed correctly. Oracle documents one possible source: C:Program FilesCommon FilesOracleJavajavapath can precede the intended JDK. Use where java and where javac to see every match. Move the intended JDK entry ahead of stale entries or remove entries you no longer need; do not delete a directory just because it appears in a diagnostic without first confirming what uses it. Oracle recommends avoiding multiple active JDK bin directories in the effective path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recover from a bad edit

If Java or other commands stopped working after editing Path, return to Environment Variables and inspect the entries. Restore any removed original entries from a backup or your organization’s instructions, remove only confirmed stale Java entries, and add the intended %JAVA_HOME%bin entry. Avoid pasting a replacement over the entire existing Path. Reopen the terminal and verify again. A user-level change can be removed from the user variables without altering other accounts’ settings.

Use more than one JDK

For a single JDK, a persistent JAVA_HOME and matching PATH are usually enough. If you have several installations and switch occasionally, change JAVA_HOME and ensure the matching bin directory comes first in the effective PATH; then verify both location and version. On Linux, alternatives may select system commands, but that selection and JAVA_HOME are separate configuration choices.

For projects with different Java requirements, a version manager or project-level setting is less error-prone than manually editing global variables each time. SDKMAN! is available on macOS, Linux, and WSL and supports multiple JDK vendors. Its identifiers change as releases appear, so copy a current identifier from sdk list java:

sdk list java
sdk install java <identifier>
sdk use java <identifier>
sdk default java <identifier>

sdk use selects a version for the current shell; sdk default sets the default managed version. Other approaches include jEnv or asdf on Unix-like systems, Maven Toolchains, IDE-specific project SDKs, and carefully managed Windows environment variables. Keep in mind that a project’s required Java version may be different from the latest release installed on your computer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure the IDE and build tool separately

System PATH is not the only source of Java selection. In IntelliJ IDEA, check the project and module SDK settings; in Eclipse, check Installed JREs and the project execution environment; in VS Code, check Java runtime configuration; in NetBeans, check the configured Java platform. Labels can vary by product version. An IDE may run itself on a bundled runtime while a project uses a separate JDK, so the IDE opening successfully does not establish that the project compiler is configured correctly.

Maven, Gradle, and Android Studio can also select a JDK through their own settings, toolchains, or launch configuration. If a build uses a different version from the terminal, inspect the build tool’s Java details and project configuration rather than repeatedly changing PATH. In CI pipelines and services, select the JDK explicitly and log JAVA_HOME, java -version, and javac -version; do not rely on an interactive shell startup file.

Test compilation and execution

To confirm that the compiler and launcher both work, create a file named Hello.java:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Java path setup works.");
    }
}

Compile and run it from that directory:

javac Hello.java
java Hello

The expected output is:

Java path setup works.

Java 11 and later can also run a source file directly with java Hello.java. For a development setup, still test javac explicitly: source-file mode does not prove the compiler command is available on your path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When you may not need to edit PATH manually

If a version manager, managed workstation, IDE, container, or CI system selects the JDK for you, follow that environment’s configuration rather than adding another competing global path. For a one-off command, a full executable path or a temporary session setting may be sufficient. For everyday terminal and build-tool use, configure the JDK root and command path deliberately, then verify what each tool actually selects.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.