Java, a cornerstone of modern software development, powers everything from enterprise applications and web servers to mobile apps and even embedded systems. Its “write once, run anywhere” philosophy has made it incredibly versatile and widely adopted. Installing Java on your system is a fundamental step for any aspiring developer or IT professional. This guide will walk you through the process of installing the Java Development Kit (JDK), the essential toolset for Java programming.
Understanding Java Versions and Editions
Before diving into the installation process, it’s crucial to understand the different versions and editions of Java available. This ensures you install the right software for your needs.

Java Development Kit (JDK) vs. Java Runtime Environment (JRE)
The most common confusion arises between the JDK and the JRE.
- Java Runtime Environment (JRE): The JRE is the component that allows you to run Java applications. It contains the Java Virtual Machine (JVM), core libraries, and supporting files. If you only need to execute existing Java programs, the JRE is sufficient.
- Java Development Kit (JDK): The JDK is a superset of the JRE and includes everything needed to develop Java applications. It contains the JRE, plus development tools like the compiler (
javac), debugger (jdb), archiver (jar), and other utilities. For anyone planning to write Java code, the JDK is essential.
Oracle JDK vs. OpenJDK
Oracle is the commercial steward of Java, and they offer their own JDK builds. However, the open-source reference implementation of Java is called OpenJDK.
- Oracle JDK: Historically, Oracle JDK was the de facto standard. While still available, its licensing for commercial use has changed over time, necessitating careful review. Oracle offers Long-Term Support (LTS) releases for extended periods.
- OpenJDK: OpenJDK is freely available and is the basis for many other JDK distributions. Most Linux distributions, for instance, provide OpenJDK packages. It’s an excellent choice for development and often preferred for its open-source nature and flexible licensing.
Long-Term Support (LTS) Releases
Oracle and other vendors designate certain Java versions as Long-Term Support (LTS) releases. These versions receive updates and security patches for an extended period, typically several years. As of late 2023 and early 2024, key LTS versions include Java 8, Java 11, and Java 17. Newer non-LTS versions are released every six months, offering the latest features but with shorter support cycles. For most development projects, especially in enterprise environments, choosing an LTS version is recommended.
Installing Java on Windows
Installing Java on a Windows system is a straightforward process, typically involving downloading an installer and following a guided setup.
Downloading the JDK
- Identify the Version: Decide which Java version you need. For general development and learning, the latest LTS version (e.g., Java 17 or the newest available LTS) is a good starting point. For specific project requirements, you might need an older version like Java 11 or Java 8.
- Choose a Distribution: You can download the Oracle JDK or an OpenJDK distribution like Adoptium Temurin.
- Oracle JDK: Visit the Oracle Java SE Downloads page. Select the desired version and then choose the “Windows” tab. Download the “x64 Installer” for most modern systems.
- OpenJDK (Adoptium Temurin): Go to the Adoptium website (adoptium.net). Navigate to the “Releases” section. Select the desired LTS version (e.g., JDK 17) and download the “Windows x64” installer (
.msifile).
- Locate the Download: Once the download is complete, find the
.exeor.msifile in your Downloads folder.
Running the Installer
- Execute the Installer: Double-click the downloaded installer file. You may need administrator privileges to proceed.
- Accept Defaults or Customize: The installer will typically present a “Welcome” screen. Click “Next.”
- Typical Installation: For most users, accepting the default installation location is recommended. This will install the JDK in a path similar to
C:Program FilesJavajdk-<version>. - Custom Installation: If you need to specify a different installation directory, click “Custom” and choose your preferred location. For beginners, the default is usually best.
- Typical Installation: For most users, accepting the default installation location is recommended. This will install the JDK in a path similar to
- Accept Defaults (Continued): The installer will then prompt you about installing the JRE. Since the JDK already includes a JRE, you can generally accept the default options here. Click “Next.”
- Installation Progress: The installer will copy files and configure your system. This may take a few minutes.
- Completion: Once the installation is finished, you’ll see a confirmation screen. Click “Close.”
Setting Up Environment Variables (Crucial Step)
For the Windows command prompt or PowerShell to find and use the Java commands (like java and javac), you need to configure environment variables.
- Open System Properties:
- Right-click on “This PC” (or “My Computer”) on your desktop or in File Explorer.
- Select “Properties.”
- In the System window, click on “Advanced system settings” on the left pane.
- Access Environment Variables: In the “System Properties” window, click the “Environment Variables…” button at the bottom.
- Create/Edit
JAVA_HOME:- Under “System variables” (or “User variables” if you only want it for your user account), look for a variable named
JAVA_HOME. - If
JAVA_HOMEdoes not exist, click “New…”- Variable name:
JAVA_HOME - Variable value: Enter the path to your JDK installation directory (e.g.,
C:Program FilesJavajdk-17.0.1). Ensure this path points to the JDK’s root directory, not a subfolder likebin.
- Variable name:
- If
JAVA_HOMEalready exists, select it, click “Edit…”, and update its value to the correct JDK installation path.
- Under “System variables” (or “User variables” if you only want it for your user account), look for a variable named
- Edit
PathVariable:- In the “System variables” list, find the
Pathvariable. - Select it and click “Edit…”.
- In the “Edit Environment Variable” window, click “New.”
- Add a new entry:
%JAVA_HOME%bin - This tells Windows to look for Java executables within the
bindirectory of yourJAVA_HOMEpath. - Important: Ensure this new entry is placed near the top of the list, especially if you have multiple Java versions installed, to control which one is prioritized. You can use the “Move Up” button.
- In the “System variables” list, find the
- Confirm and Close: Click “OK” on all open windows (Edit Environment Variable, Environment Variables, System Properties) to save your changes.
Verifying the Installation
To confirm that Java is installed and configured correctly:
- Open Command Prompt or PowerShell:
- Press
Windows Key + R, typecmd(orpowershell), and press Enter.
- Press
- Check Java Version: Type the following command and press Enter:
bash
java -version
You should see output displaying the Java version you installed (e.g.,java version "17.0.1"). - Check Java Compiler Version: Type the following command and press Enter:
bash
javac -version
This should also display the compiler version, confirming that the JDK was installed correctly and thebindirectory is in yourPath.
If either of these commands returns an error like “‘java’ is not recognized as an internal or external command,” it means the environment variables are not set up correctly, or you haven’t restarted your command prompt after making the changes. Close and reopen your command prompt/PowerShell and try again.
Installing Java on macOS
macOS users have a streamlined experience for installing Java, often leveraging the brew package manager or direct downloads.
Using Homebrew (Recommended)
Homebrew is a popular package manager for macOS, simplifying the installation of many software packages, including Java.

- Install Homebrew (if not already installed):
- Open your “Terminal” application (Applications > Utilities > Terminal).
- Paste the following command and press Enter. Follow the on-screen prompts.
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Update Homebrew: After installation, it’s good practice to update Homebrew:
bash
brew update
- Search for Java: To see available Java distributions:
bash
brew search jdk
This will list various JDKs, including Oracle’s and OpenJDK variants. - Install a JDK: For example, to install OpenJDK (Adoptium Temurin) version 17:
bash
brew install --cask temurin@17
Or, if you prefer Oracle JDK (note: Oracle JDK might require manual setup ofJAVA_HOMEsimilar to Windows):
bash
brew install --cask oracle-jdk
Note: Package names can change. If a specific command fails, search again usingbrew search jdkand adapt the command. - Homebrew’s Automatic Configuration: Homebrew typically handles setting up the necessary environment variables for you when using
--caskinstallations.
Manual Installation (Oracle JDK or specific OpenJDK builds)
- Download the JDK:
- Visit the Oracle Java SE Downloads page or the Adoptium website.
- Select the “macOS” tab.
- Download the
.dmgdisk image file for your desired JDK version.
- Run the Installer:
- Double-click the downloaded
.dmgfile. - A virtual disk will mount. Double-click the
.pkginstaller file within it. - Follow the on-screen prompts to complete the installation. The installer typically places Java in
/Library/Java/JavaVirtualMachines/.
- Double-click the downloaded
- Setting Up Environment Variables (if needed): Homebrew often manages this, but if you install manually and commands aren’t found, you might need to set
JAVA_HOME.- Find your JDK installation: Look in
/Library/Java/JavaVirtualMachines/. You’ll see folders likejdk-17.jdk. - Determine the
JAVA_HOMEpath: This will be something like/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home. - Edit your shell profile: Open your shell’s configuration file. For Bash, it’s usually
~/.bash_profile. For Zsh (the default on newer macOS), it’s~/.zshrc.
bash
# Example for .zshrc
nano ~/.zshrc
- Add the following lines:
bash
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home" # Adjust path as needed
export PATH="$JAVA_HOME/bin:$PATH"
- Save and exit: Press
Ctrl+X, thenY, then Enter to save and exit nano. - Apply changes: Either close and reopen your Terminal, or run:
bash
source ~/.zshrc # Or source ~/.bash_profile
- Find your JDK installation: Look in
Verifying the Installation
- Open Terminal:
- Check Java Version:
bash
java -version
- Check Java Compiler Version:
bash
javac -version
You should see output indicating the installed Java version.
Installing Java on Linux
Linux distributions offer various ways to install Java, from package managers to manual downloads. Using the distribution’s package manager is generally the easiest and most recommended method.
Using Package Managers (Debian/Ubuntu)
- Update Package List:
bash
sudo apt update
- Search for Available Java Packages:
bash
apt search openjdk
This will show available OpenJDK versions (e.g.,openjdk-11-jdk,openjdk-17-jdk). - Install a JDK:
bash
sudo apt install openjdk-17-jdk
Replaceopenjdk-17-jdkwith the package name for the version you want. Thejdkpackage includes the JRE and development tools. - Verify Installation:
bash
java -version
javac -version
Using Package Managers (Fedora/CentOS/RHEL)
- Update Package List:
bash
sudo dnf update # For Fedora, newer CentOS/RHEL
# or
sudo yum update # For older CentOS/RHEL
- Search for Available Java Packages:
bash
sudo dnf search openjdk # or sudo yum search openjdk
- Install a JDK:
bash
sudo dnf install java-17-openjdk-devel # For Fedora, newer CentOS/RHEL
# or
sudo yum install java-17-openjdk-devel # For older CentOS/RHEL
The-develpackage usually corresponds to the JDK. Adjust the version number as needed. - Verify Installation:
bash
java -version
javac -version
Manual Installation (Tarball)
This method is useful if you need a specific version not available in your distribution’s repositories or if you prefer a portable installation.
- Download the JDK:
- Go to Oracle Java SE Downloads or Adoptium.
- Select the “Linux” tab.
- Download the compressed archive (
.tar.gz) file.
- Extract the Archive:
- Create a directory to store your Java installations, for example,
/usr/local/java.
bash
sudo mkdir -p /usr/local/java
cd /usr/local/java
- Extract the downloaded tarball (replace
jdk-17.0.1_linux-x64_bin.tar.gzwith your downloaded file name):
bash
sudo tar -xvzf /path/to/your/downloaded/jdk-17.0.1_linux-x64_bin.tar.gz
- This will create a directory like
jdk-17.0.1within/usr/local/java.
- Create a directory to store your Java installations, for example,
- Set Up Environment Variables:
- You’ll need to configure
JAVA_HOMEand add Java to yourPATH. This is typically done by editing/etc/profileor a file in/etc/profile.d/. - Create a new file, for example,
/etc/profile.d/jdk.sh:
bash
sudo nano /etc/profile.d/jdk.sh
- Add the following lines, adjusting the path to your extracted JDK directory:
bash
export JAVA_HOME=/usr/local/java/jdk-17.0.1
export PATH=$JAVA_HOME/bin:$PATH
- Save and exit the editor.
- Make the script executable:
bash
sudo chmod +x /etc/profile.d/jdk.sh
- Apply the changes. You can either log out and log back in, or source the file:
bash
source /etc/profile.d/jdk.sh
- You’ll need to configure
- Verify Installation:
bash
java -version
javac -version
Managing Multiple Java Versions (Linux)
Linux systems often have a utility called update-alternatives to manage multiple versions of commands, including java and javac.
- List available Java alternatives:
bash
sudo update-alternatives --config java
sudo update-alternatives --config javac
- Select your desired Java version: The command will present a list of installed Java versions. Enter the number corresponding to the version you want to use as the default. This is a powerful way to switch between different JDKs without manually altering environment variables.
Post-Installation Best Practices and Next Steps
Once Java is installed, consider these practices for a smooth development experience.
IDE Setup
Integrated Development Environments (IDEs) like IntelliJ IDEA, Eclipse, and VS Code significantly enhance Java development. You’ll typically need to configure your IDE to point to your installed JDK.
- IntelliJ IDEA: During project creation or in Project Structure settings, you can select the JDK.
- Eclipse: In Preferences > Java > Installed JREs, you can add or select your JDK.
- VS Code: Install the “Extension Pack for Java” from Microsoft. It will guide you in detecting or selecting your JDK.
Keeping Java Updated
Software evolves, and so does Java. Regularly check for updates, especially for your chosen LTS version, to benefit from security patches and bug fixes. For OpenJDK distributions installed via package managers, running system updates (sudo apt upgrade, sudo dnf upgrade, etc.) will often update your Java installation. For Oracle JDK or manual installs, you’ll need to download and install newer versions periodically.
Understanding the JVM
The Java Virtual Machine (JVM) is the heart of the Java platform. While you don’t typically install it separately from the JDK or JRE, understanding its role—interpreting bytecode and managing memory (garbage collection)—is fundamental to mastering Java performance and troubleshooting.

Starting Your First Java Program
With Java installed, you’re ready to write your first program. A simple “Hello, World!” program is the traditional starting point.
- Create a file:
HelloWorld.java - Add code:
java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
- Compile: Open your terminal/command prompt, navigate to the directory where you saved the file, and run:
bash
javac HelloWorld.java
This createsHelloWorld.class. - Run:
bash
java HelloWorld
You should see “Hello, World!” printed to your console.
This successful compilation and execution signify that your Java installation is fully functional, opening the door to a vast world of Java development.
