How to Install Java JDK on Windows/Mac/Linux Step by Step

How to Install Java JDK on Windows/Mac/Linux Step by Step

If you’ve ever wanted to learn Java programming, the very first thing you need is the Java Development Kit (JDK). Without the JDK, writing and running Java programs simply isn’t possible. But don’t worry—I’ll walk you through how to install Java JDK on Windows, Mac, and Linux systems step by step.

Whether you’re an absolute beginner or just reinstalling Java for a fresh start, this guide is designed to make your installation process hassle-free. By the end of this guide, you’ll have Java installed on your machine and ready to start coding!

Let’s dive in!

What is Java JDK?

Before we jump into how to install Java JDK, let’s quickly understand what exactly the JDK is.

JDK (Java Development Kit) is a software development kit provided by Oracle (and other vendors) for developing Java applications. It includes:

  • JRE (Java Runtime Environment): To run Java applications.
  • Compiler (javac): To convert Java code into machine-readable code.
  • Development Tools: Debuggers, documentation generator, and more.

If you want to write Java code and run it, the JDK is your starting point.

How to Install Java JDK on Windows (Step by Step)

1. Download the JDK

  1. Go to the official Oracle website: https://www.oracle.com/java/technologies/downloads/
  2. Scroll to JDK Downloads and choose the latest version.
  3. Select the Windows Installer (x64).
  4. Click Download and accept the license agreement if prompted.
How to Install Java JDK

2. Install the JDK

  1. Locate the downloaded .exe file (usually in your Downloads folder).
  2. Double-click to run the installer.
  3. Follow the installation wizard:
    • Next → choose destination folder → Next → Install → Finish

3. Set Environment Variables

  1. Right-click This PC → Properties → Advanced system settings
  2. Click on Environment Variables
  3. Under System Variables, find Path, select it, and click Edit.
  4. Add a new entry:
    Example (may vary):
    C:\Program Files\Java\jdk-21\bin
  5. Click OK on all windows to save.
How to Install Java JDK

4. Verify Installation

  1. Open Command Prompt and type: java -version
  2. You should see the installed version displayed.

Congratulations! You’ve successfully installed Java JDK on Windows.

How to Install Java JDK on Mac (Step by Step)

Step 1: Download the JDK

  1. Download the .DMG file from the Oracle official website
How to Install Java JDK

2. Open the .DMG file install the JDK by following on screen instructions

JDK installation

Step 2: Configure Java Path (Optional but recommended)

📌 Step 1: Find the Installed Java Version

First, check where Java is installed:

bash
/usr/libexec/java_home -V

Example output:

swift
Matching Java Virtual Machines (1):
21 (x86_64) "Oracle JDK 21" /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home

📌 Step 2: Set JAVA_HOME Environment Variable

Now, you’ll set the JAVA_HOME path based on the installation location.

Add this line to your shell configuration file:

  • For zsh (default in modern macOS):
bash
nano ~/.zshrc
  • For bash:
bash
nano ~/.bash_profile

Add the following line to the file:

bash
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH

📌 Step 3: Apply the Changes

After adding it, apply the changes by running:

bash
source ~/.zshrc

or

bash
source ~/.bash_profile

📌 Step 4: Verify the JAVA_HOME

Check that it’s set correctly:

bash
echo $JAVA_HOME

And confirm the version:

bash
java -version

✅ Example Output

/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
java version "21" 2024-03-19

Now you’ve successfully set the Java Path in Mac OS!

How to Install Java JDK on Linux (Step by Step)

Depending on your Linux distribution, the process may vary slightly.

Step 1: Update System Packages

bash
sudo apt-get update

Step 2: Install OpenJDK

For Ubuntu/Debian systems:

bash
sudo apt-get install openjdk-21-jdk

Step 3: Verify Installation

bash
java -version

Step 4: Setting Default Java (Optional)

bash
sudo update-alternatives --config java

Follow the on-screen instructions to set the default version.

Now you’ve successfully completed how to install Java JDK on Linux!

Which Version of Java JDK Should You Install?

  • For beginners: Start with the latest stable release (e.g., Java 21 or Java 17 LTS).
  • For compatibility: If you’re working on legacy projects, you may need older versions like Java 8.

Common Issues During Installation (And How to Fix Them)

IssueSolution
java not recognized as commandCheck your environment variable setup.
Installer won’t runTry running as Administrator.
Version mismatchEnsure the correct Path is used.

Why Do You Need Java JDK?

  • To write Java programs.
  • To compile your source code into executable code.
  • To run applications that require specific Java libraries.

Without the JDK, learning Java is like trying to build a house without any tools.

Helpful Tips for Beginners Learning Java

Now that you’ve installed the JDK, what next? Here are some practical tips:

  1. Start with Basics: Learn data types, loops, and methods.
  2. Use IDEs: Start with IntelliJ IDEA or Eclipse.
  3. Practice: Websites like LeetCode, HackerRank, and CodeChef are excellent for practice.
  4. Learn Object-Oriented Concepts: Java is fundamentally OOP-based.
  5. Write Small Programs: Build confidence with mini-projects like calculators or to-do lists.

Conclusion

Learning how to install Java JDK is your first step toward becoming a Java programmer. Whether you’re using Windows, Mac, or Linux, the installation process is straightforward when you follow the steps provided here.

Once installed, you’re all set to begin your journey into Java programming!

If you found this guide helpful, don’t forget to bookmark this page or share it with your fellow programmers. And if you have any questions, drop them in the comments below—I’m here to help!