Course contentsShow
Java
Lesson 6 of 2,8701. Java Setup and First ProgramFree lesson

Adding Java to Your System PATH

Updating the PATH environment variable to enable running java and javac commands from any terminal or command prompt.

Adding Java to Your System PATH

What you'll learn: How to make the java and javac commands available from any terminal or command prompt on your computer.

Why This Matters

Imagine you've installed a new tool in your garage, but you have to walk to a specific corner every time you want to use it. Frustrating, right? That's what happens if you don't add Java to your PATH. Without it, you'd need to type the full location of the Java commands (like C:\Program Files\Java\jdk-17\bin\java) every single time you want to run a Java program.

The PATH is like a shortcut list your operating system maintains. When you type a command like java or javac, your system checks the PATH to find where those programs live. By adding Java's bin folder to your PATH, you're telling your system: "Hey, when I type java, look in this folder!"

How It Works

When you installed the JDK (step 4), all the command-line tools ended up in a folder typically called bin (short for "binary"). This folder contains java.exe, javac.exe, and other executables. By adding this folder to your PATH environment variable, you enable your system to find these tools from anywhere.

On Windows: You'll add something like C:\Program Files\Java\jdk-17\bin to your PATH variable through System Properties.

On macOS/Linux: You'll typically edit your shell configuration file (.bash_profile, .zshrc, etc.) to include the JDK's bin directory.

Once configured, you can open any terminal or command prompt, type java -version or javac, and your system will know exactly what you mean.

Key Takeaway: Adding Java to your PATH lets you run java and javac commands from anywhere on your system, eliminating the need to type long directory paths every time.