Java Environment Setup – Install JDK and Set PATH

⏱️ 6 min read • Beginner Level • Lesson 5

Lesson 5 of 124 of Java Tutorial
You have completed this lesson

Completed on . You can revise this lesson or continue to the next topic.

Before you start writing Java programs, you need to set up the Java environment. This means installing the Java Development Kit (JDK), configuring the PATH variable, and verifying that Java commands work correctly from the terminal or command prompt.

If you are new to Java, you may first read the Java introduction lesson and then continue with this setup guide.


What You Need for Java Setup

  • To compile and run Java programs, you need the Java Development Kit (JDK).

  • The JDK includes important tools like javac for compiling Java source code and java for running Java programs.

  • After installation, the PATH environment variable helps your system locate Java commands from any folder.

  • The setup process differs slightly for Windows, Linux, and macOS.

Download and Install JDK

You can install JDK from Oracle JDK or an OpenJDK distribution. Choose the installer according to your operating system and system architecture.

Important: If you are a beginner, install the latest stable JDK version and remember the installation folder because you may need its bin path while setting environment variables.

How to Set Java PATH on Windows

  1. Step 1: Check the JDK installation directory and copy the \bin path.
    Example: C:\Program Files\jdk-21\bin
    Java JDK installation directory on Windows
  2. Step 2: Open System Properties.
    Press Windows + R, type sysdm.cpl, and press Enter.
    Open System Properties in Windows
  3. Step 3: Click the Advanced tab and then click Environment Variables....
    Environment Variables option in Windows
  4. Step 4: In the User Variables section, edit the Path variable and add the JDK bin path.
    Note: Do not delete existing values. Only add the JDK path as a new entry.
    Adding Java PATH in Windows
  5. Step 5: Verify the Java path setup.
    Open Command Prompt and run:
    Windows Command
    javac -version
    Open Command Prompt in Windows
    If the setup is correct, it will display the installed Java compiler version.
    Verify Java path setup successfully

How to Set Java PATH on Linux / Solaris

To check if Java is installed, run:

Terminal
java -version

If it shows command not found or an older version, you need to install Java or update the PATH.

C shell (csh):

csh
set path=(/usr/local/jdk/bin $path)

Bash shell:

bash
PATH=/usr/local/jdk/bin:$PATH
export PATH

sh shell:

sh
PATH=/usr/local/jdk/bin:$PATH
export PATH

After updating PATH, reload your shell configuration file and verify with:

Verify
java -version

How to Set Java PATH on macOS

On macOS, you can use the java_home tool to detect installed Java versions.

macOS Terminal
/usr/libexec/java_home -V

To check the Java compiler version, run:

Verify javac
javac -version
Summary:
  • Install JDK before writing and running Java programs.
  • Set the PATH variable so Java commands work from the command line.
  • Use java -version and javac -version to verify your setup.
  • The setup steps are slightly different for Windows, Linux, and macOS.

Interview Questions ⭐

To compile and run Java programs, you need to install the Java Development Kit, also called JDK.

The PATH variable allows the operating system to find Java tools like javac and java from the command line.

Next step: Learn the Java Program Structure.

🧠 Test your understanding with a quick quiz



🚀 Quick Knowledge Check

Topic: Java_environment_setup | Language: Java

Question 1 of 7
Q1. What does JDK stand for in Java?
Q2. On macOS, which tool helps manage multiple Java versions?
Q3. On Linux (bash shell), how do you add JDK to the PATH?
Q4. Which component of Java includes both the compiler and runtime environment?
Q5. Which command is used to verify Java compiler installation in Windows?
Q6. Why do we set the PATH environment variable in Java installation?
Q7. What is the default JDK installation directory in Windows?

🎉 Great job! Continue learning Java step by step.

Discussion

Ask questions, share suggestions, or discuss this lesson.

Please login or create an account to join the discussion and save your learning activity.

Loading comments...

Have you completed this lesson?

Mark this lesson as completed to track your learning progress. To keep track across devices, please login and save your learning progress.

Not completed yet.