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
- Search for Environment Variables in the Start menu.
- Select
Pathunder System variables and click Edit. - Click New and paste the JDK
binfolder, for exampleC:\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.