How to Set Java Environment Variables (Windows, Mac & Linux) | JAVA_HOME Setup

📌Set Java Environment Variables

Introduction

When you install Java (JDK), you must configure environment variables so your system can run Java commands like java and javac globally. In this guide, we’ll learn how to set up JAVA_HOME and update the PATH variable on Windows, macOS, and Linux.


🔹 Step 1: Install JDK

  • Download the latest JDK from Oracle Java Downloads.

  • Install it on your system.

    • Windows Default Path: C:\Program Files\Java\jdk-17

    • macOS Path: /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home

    • Linux Path: /usr/lib/jvm/java-17-openjdk-amd64


🔹 Step 2: Set JAVA_HOME and PATH

🖥️ Windows

  1. Right-click This PC → Properties → Advanced system settings.

  2. Go to Advanced → Environment Variables.

  3. Under System variables, click New:

    • Variable name: JAVA_HOME

    • Variable value: C:\Program Files\Java\jdk-17

  4. Edit the Path variable → Add:

    %JAVA_HOME%\bin

    Note:

    • If you don’t want to use JAVA_HOME, you can directly add:

      C:\Program Files\Java\jdk-17\bin
    • This step is not strictly required if you already followed step 3 and 4, but it’s another way to make Java accessible system-wide.

🍏 macOS

  1. Open Terminal.

  2. Edit the shell profile (depends on shell):

    • For zsh (default in macOS Catalina+):

      nano ~/.zshrc
    • For bash:

      nano ~/.bash_profile
  3. Add the following lines:

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
    export PATH=$JAVA_HOME/bin:$PATH ⚡ Note: If you don’t want to rely on JAVA_HOME, you can directly add the bin path instead: export PATH=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin:$PATH
    • This step is not strictly required if you already followed step 3, but it’s another way to make Java accessible system-wide.

  4. Save the file, then run:

    source ~/.zshrc

🐧 Linux

  1. Open Terminal.

  2. Edit your profile file:

    nano ~/.bashrc
  3. Add the following lines:

    export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH
    Note: If you don’t want to rely on JAVA_HOME, you can directly add the bin path instead: export PATH=/usr/lib/jvm/java-17-openjdk-amd64/bin:$PATH
    • This step is not strictly required if you already followed step 3 and 4, but it’s another way to make Java accessible system-wide.

  4. Save the file and refresh:

    source ~/.bashrc

🔹 Step 3: Verify Installation

Open a terminal/command prompt and type:

java -version javac -version

If configured correctly, it will display the installed Java version.

👉Watch Set Java Environment Variables in Action

Here's a quick video to help you understand to Set Java Environment Variables in Action better: Install Java JDK & Set Environment Variables | Step-by-Step Guide (Windows/Mac/Linux) | Hindi

✅ Conclusion

By setting JAVA_HOME and updating PATH, you ensure your system can compile and run Java programs globally. This setup is essential for working with Java-based tools, frameworks, and applications.


💼 Professional Support Available

If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.

Technologies covered include Java, Spring Boot, PL/SQL, Azure, and workflow automation (jBPM, Camunda BPM, RHPAM).



Comments

Popular posts from this blog

jBPM Installation Guide: Step by Step Setup

Scopes of Signal in jBPM

OOPs Concepts in Java | English | Object Oriented Programming Explained