Java Environment Setup

Before you can start coding in Java, you need to set up the right environment. This includes installing the Java Development Kit (JDK), configuring the Java Runtime Environment (JRE), and setting up the PATH variable so you can run Java programs from the command line.


  • To compile and run any Java program, you must first install and configure the Java Compiler and the Java Runtime Environment (JRE) on your system.

  • For this purpose, Java provides the JDK (Java Development Kit), which includes both the compiler and runtime.

  • You can download the JDK from the official Oracle website or OpenJDK distributions.
    Choose the installer according to your system configuration (32-bit or 64-bit).

  • After downloading, install it. The installation process is similar to other software installations.

  • Once installed, you must set the PATH environment variable to access the Java compiler from the command line.

  • The path setting process varies depending on your operating system (Windows, Linux, macOS, etc.).

How to Set Java Path on Windows

  1. Step 1: Check the JDK installation directory and copy the \bin path.
    Default location: C:\Program Files\Java\jdk1.8.0_25\bin
    Java JDK installation directory - prowessapps.com
  2. Step 2: Right-click on My ComputerProperties.
    Windows system properties - prowessapps.com
  3. Step 3: Click on Advanced system settings.
    Advanced system settings for Java PATH - prowessapps.com
  4. Step 4: Click on the Environment Variables... button.
    Set Environment Variables in Windows - prowessapps.com
  5. Step 5: In the User Variables section, add or edit the PATH variable.
    Paste the copied JDK path in the value box. If PATH already exists, append the new value at the end separated by a semicolon (;).
    Note: Do not delete existing values. Only add the JDK path at the end.
    Adding Java PATH in Windows - prowessapps.com
  6. Step 6: Verify the path setup.
    Open Command Prompt (Windows + R → type cmd) and run:
    javac -version If installed correctly, it will display the installed Java compiler version.
    Verify Java path setup - prowessapps.com

How to Set Java Path on Linux / Solaris

To check if Java is installed, run:

java -version

If it shows Command not found or an older version, you need to set the PATH.

C shell (csh):

set path=(/usr/local/jdk1.7.0/bin $path)

Bash shell:

PATH=/usr/local/jdk1.7.0/bin:$PATH export PATH

sh shell:

PATH=/usr/local/jdk1.7.0/bin:$PATH export PATH

After editing, reload your shell configuration file and verify with:

java -version

How to Set Java Path on macOS

On macOS, use the java_home tool to manage multiple Java versions:

/usr/libexec/java_home -v 1.8.0_73 --exec javac -version

Next: Your First Java Program




🚀 Quick Knowledge Check

Topic: Java_environment_setup | Language: Java

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