Java Development Kit (JDK) is an essential toolkit for developers who want to create Java applications. It contains the Java Runtime Environment (JRE), an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), and other tools needed for Java development. Installing the JDK correctly is the first step toward building and running Java applications on your computer.
This article provides a comprehensive, step-by-step guide to installing the latest version of the Java JDK on both Windows and Mac operating systems.
What is Java JDK?
Before diving into the installation process, it’s important to understand what the JDK is and why it matters.
- Java Development Kit (JDK): A software development environment used for developing Java applications and applets.
- Includes: Java Runtime Environment (JRE), development tools like the compiler (javac), debugger, and other utilities.
- Purpose: To enable developers to write, compile, run, debug, and document Java applications.
Prerequisites
- A stable internet connection to download the JDK installer.
- Administrative privileges on your computer to install software.
- Familiarity with basic command line usage (optional but helpful).
How to Install Java JDK on Windows
Step 1: Download the JDK Installer
- Open your preferred web browser.
- Visit the official Oracle JDK download page: https://www.oracle.com/java/technologies/downloads/
- Locate the latest version of Java SE Development Kit.
- Choose the Windows installer , options are typically available as
.exeor.zip. The.exeinstaller is recommended for ease of installation. - Click on the download link and accept the license agreement if prompted.
Step 2: Run the Installer
- Once downloaded, navigate to your
Downloadsfolder. - Double-click on the
.exefile to launch the installer. - If prompted by User Account Control, click Yes to allow changes.
Step 3: Follow Installation Wizard
- In the setup wizard window, click Next.
- Choose your installation folder or leave it as default (
C:\Program Files\Java\jdk-version). - Click Next again to begin installation.
- Wait for the installation process to complete.
- Click Close once done.
Step 4: Set Environment Variables
To use Java from any command prompt window, you need to set environment variables (JAVA_HOME and update PATH).
Set JAVA_HOME Variable
- Open Start Menu, search for Environment Variables, and select Edit the system environment variables.
- In the System Properties window, click Environment Variables.
- Under System variables, click New.
- Enter
JAVA_HOMEas Variable name. - For Variable value, enter your JDK installation path, e.g.,
C:\Program Files\Java\jdk-version. - Click OK.
Update PATH Variable
- In Environment Variables window under System variables, find and select
Path. - Click Edit.
- Click New, then add
%JAVA_HOME%\bin. - Click OK in all windows to apply changes.
Step 5: Verify Installation
- Open Command Prompt (
cmd.exe). - Type
java -versionand press Enter , this shows the installed JRE version. - Type
javac -versionand press Enter , this shows installed compiler version.
If both commands return version information without errors, you have successfully installed Java JDK on Windows.
How to Install Java JDK on Mac
Step 1: Download the JDK Installer for Mac
- Open Safari or any browser.
- Visit Oracle’s official download page: https://www.oracle.com/java/technologies/downloads/
- Find the latest macOS version of Java SE Development Kit.
- Download either
.dmgor.pkginstaller ,.dmgis common on macOS.
Step 2: Install Using Installer Package
- Once downloaded, open Finder and go to your Downloads folder.
- Double-click the
.dmgfile to mount it. - A new window will appear with an installer package (
jdk-version.pkg). - Double-click this file to start installation.
- Follow on-screen instructions:
- Click Continue
- Agree to software license terms
- Select target disk
- Click Install
- Enter your Mac administrator password when prompted.
- Wait for installation to complete, then click Close.
Step 3: Verify Installation via Terminal
- Open Terminal app (you can find it via Spotlight or in Applications > Utilities).
- Type
java -versionand press Enter , this shows installed runtime version. - Type
javac -versionand press Enter , this shows installed compiler version.
If both commands display versions without errors, installation is successful.
Step 4: Set JAVA_HOME Environment Variable (Optional)
Most macOS setups automatically configure JAVA_HOME, but if you need to set or confirm it:
- Open Terminal.
- To find out where JDK is installed, type:
bash
/usr/libexec/java_home
-
This command outputs the path of your current JDK installation, e.g.,
/Library/Java/JavaVirtualMachines/jdk-version.jdk/Contents/Home. -
To set
JAVA_HOMEtemporarily in Terminal session:
bash
export JAVA_HOME=$(/usr/libexec/java_home)
-
To make this change permanent:
-
Open or create your shell configuration file (
~/.zshrcfor zsh or~/.bash_profilefor bash):bash
nano ~/.zshrc -
Add this line at the end:
bash
export JAVA_HOME=$(/usr/libexec/java_home) -
Save file (
Ctrl + O, then Enter) and exit (Ctrl + X). - Run
source ~/.zshrcto reload configuration.
Troubleshooting Common Issues
Even with straightforward instructions, users might face some common issues during installation:
Issue: ‘java’ or ‘javac’ Not Recognized
- On Windows, double-check that
%JAVA_HOME%\binis correctly added to PATH environment variable. - Restart Command Prompt or reboot computer after setting environment variables.
Issue: Incorrect Version Shown
- Check if multiple versions of JDK are installed; remove older versions if necessary.
- Use full path commands like
"C:\Program Files\Java\jdk-version\bin\java" -version.
Issue: Permission Denied During Installation
- Make sure you have administrator rights when installing software on both Windows and macOS.
- On macOS, try running Terminal commands with
sudo, but avoid using sudo for regular usage.
Additional Tips for Java Developers
- Always install the latest Long-Term Support (LTS) version unless you explicitly need a specific earlier release.
- Regularly update your JDK installation to benefit from security patches and performance improvements.
- Consider using OpenJDK distributions like AdoptOpenJDK or Amazon Corretto if Oracle licensing terms do not fit your needs.
- Use Integrated Development Environments (IDEs) like Eclipse, IntelliJ IDEA, or NetBeans that detect installed JDKs automatically for smoother development workflows.
Conclusion
Installing Java JDK on Windows and Mac computers is straightforward when following official steps carefully:
- Download from Oracle’s website or trusted OpenJDK sources.
- Run installers appropriate for your OS (.exe for Windows; .dmg/.pkg for Mac).
- Set environment variables like
JAVA_HOMEand update PATH so that you can use java commands globally in terminal or command prompt. - Verify installation by checking versions with
java -versionandjavac -version.
With these steps completed successfully, you are now ready to start developing and running Java applications on your machine!
Related Posts:
Java
- Introduction to Java Collections Framework
- How to Use Java Arrays Effectively
- How to Serialize and Deserialize Objects in Java
- Using Java Collections: Lists, Sets, and Maps Overview
- How to Implement Inheritance in Java Programming
- Step-by-Step Guide to Java Exception Handling
- Writing Unit Tests in Java with JUnit
- How to Build REST APIs Using Java Spring Boot
- How to Use Java Streams for Data Processing
- How to Debug Java Code Using Popular IDE Tools
- Essential Java Syntax for New Developers
- Java Programming Basics for Absolute Beginners
- Tips for Improving Java Application Performance
- How to Debug Java Code Efficiently
- How to Set Up Java Development Environment
- Top Java Programming Tips for Beginners
- How to Deploy Java Applications on AWS Cloud
- Multithreading Basics: Creating Threads in Java
- Java Data Types Explained with Examples
- Java String Manipulation Techniques You Need to Know
- Understanding Java Classes and Objects in Simple Terms
- How to Handle File I/O Operations in Java
- How to Implement Multithreading in Java
- Object-Oriented Programming Concepts in Java
- Using Annotations Effectively in Java Development
- Exception Handling in Java: Try, Catch, Finally Explained
- How to Connect Java Applications to MySQL Database
- How to Write Your First Java Console Application
- How to Build a Simple REST API with Java Spring Boot
- How to Connect Java Programs to a MySQL Database