Java Installation Guide

Getting the Java Development Kit

Oracle provides free downloads of the Java Development Kit (JDK). Current major LTS versions include JDK 25, JDK 21, JDK 17, JDK 11, and JDK 8.

Official download page: https://www.oracle.com/java/technologies/downloads/

Installation on Windows

Using the Installer

  1. Visit the Oracle official download page and select the Windows version of JDK
  2. Download the x64 Installer (exe file) or MSI Installer
  3. Run the downloaded installer
  4. Follow the installation wizard to complete the installation. Default path is C:\Program Files\Java\jdk-version
  5. After installation, verify the installation was successful

Using the Compressed Archive

  1. Download the x64 Compressed Archive (zip file)
  2. Extract to a designated directory, such as C:\Java\jdk-25
  3. Configure environment variables

Configuring Environment Variables

  1. Right-click "This PC" and select "Properties"
  2. Click "Advanced system settings"
  3. Click "Environment Variables"
  4. Under System Variables, click "New"
    • Variable name: JAVA_HOME
    • Variable value: JDK installation path (e.g., C:\Program Files\Java\jdk-25)
  5. Find the Path variable and click "Edit"
  6. Add new variable: %JAVA_HOME%\bin
  7. Click OK to save

Verifying Installation

Open Command Prompt and enter:

java -version
javac -version

If version information appears, the installation was successful.

Installation on Linux

Installing from Compressed Archive

  1. Download the Linux version of JDK (tar.gz format)
  2. Open terminal and extract to the designated directory:
sudo mkdir -p /usr/local/java
sudo tar -zxf jdk-25_linux-x64_bin.tar.gz -C /usr/local/java
  1. Configure environment variables by editing ~/.bashrc or /etc/profile:
export JAVA_HOME=/usr/local/java/jdk-25
export PATH=$JAVA_HOME/bin:$PATH
  1. Apply the configuration:
source ~/.bashrc
  1. Verify installation:
java -version

Installing with Package Manager

Ubuntu/Debian

sudo apt update
sudo apt install openjdk-21-jdk

CentOS/RHEL

sudo yum install java-21-openjdk

Fedora

sudo dnf install java-21-openjdk

Installation on macOS

Using DMG Installer

  1. Download the macOS version of JDK (dmg file)
  2. Open the downloaded dmg file
  3. Drag JDK to the Applications folder
  4. Open terminal and configure environment variables:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
  1. Add the above to ~/.zshrc or ~/.bash_profile
  2. Verify installation:
java -version

Using Homebrew

brew install openjdk@21
sudo ln -sfn $(brew --prefix)/opt/openjdk@21/libexec/openjdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk

Managing Multiple JDK Versions

Using update-alternatives on Linux

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-21/bin/java" 1
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-17/bin/java" 2
sudo update-alternatives --config java

Switching Versions on Windows

Modify the JAVA_HOME environment variable to point to different JDK directories.

Using SDKMAN

curl -s "https://get.sdkman.io" | bash
sdk install java 21.0.5-tem
sdk install java 17.0.5-tem
sdk install java 11.0.21-tem

Verifying Java Environment

Check Java Version

java -version

Example output:

java version "25.0.1" 
Java(TM) SE Runtime Environment (build 25.0.1+12-29)
Java HotSpot(TM) 64-Bit Server VM (build 25.0.1+12-29, mixed mode)

Check Compiler Version

javac -version

Example output:

javac 25.0.1

Check JAVA_HOME

echo $JAVA_HOME  # Linux/macOS
echo %JAVA_HOME%  # Windows

Common Installation Issues

Issue 1: java command not found

Solution: Check if the Path environment variable includes the JDK's bin directory.

Issue 2: Permission denied

Solution: Use sudo for elevation on Linux/macOS, or check file permissions.

Issue 3: Port already in use

Solution: Java applications use port 8080 by default. Ensure the port is not used by other programs.

Issue 4: Difference between JDK and JRE

  • JDK (Java Development Kit): Includes development tools and JRE
  • JRE (Java Runtime Environment): Only contains components needed to run Java programs

JDK is required for developing Java programs. JRE is sufficient for running compiled Java programs.

Post-Installation Configuration Recommendations

  1. Configure MAVEN_HOME or GRADLE_HOME if using Maven or Gradle
  2. Configure M2_HOME for Maven local repository path
  3. Configure HTTP proxy if needed in enterprise environments
  4. Set timezone to ensure correct time for Java applications

Uninstalling Java

Windows Control Panel

  1. Open Control Panel
  2. Select "Programs and Features"
  3. Find Java-related programs
  4. Right-click and select "Uninstall"

Linux

sudo apt remove openjdk-*  # Debian/Ubuntu
sudo yum remove java-*    # CentOS/RHEL

macOS

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-*