Home › Java › How to Set Path in Java

How to Set Path in Java

Last updated: 28 Sep 2026

The PATH variable tells your operating system where to find javac and java. Add the JDK bin folder to it.

Windows

  1. Search for Environment Variables in the Start menu.
  2. Select Path under System variables and click Edit.
  3. Click New and paste the JDK bin folder, for example C:\Program Files\Java\jdk-21\bin.

macOS and Linux

export JAVA_HOME=/usr/lib/jvm/jdk-21
export PATH="$JAVA_HOME/bin:$PATH"

Open a new terminal and run javac -version to check it works.