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
- Visit the Oracle official download page and select the Windows version of JDK
- Download the x64 Installer (exe file) or MSI Installer
- Run the downloaded installer
- Follow the installation wizard to complete the installation. Default path is C:\Program Files\Java\jdk-version
- After installation, verify the installation was successful
Using the Compressed Archive
- Download the x64 Compressed Archive (zip file)
- Extract to a designated directory, such as C:\Java\jdk-25
- Configure environment variables
Configuring Environment Variables
- Right-click "This PC" and select "Properties"
- Click "Advanced system settings"
- Click "Environment Variables"
- Under System Variables, click "New"
- Variable name: JAVA_HOME
- Variable value: JDK installation path (e.g., C:\Program Files\Java\jdk-25)
- Find the Path variable and click "Edit"
- Add new variable: %JAVA_HOME%\bin
- 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
- Download the Linux version of JDK (tar.gz format)
- 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
- Configure environment variables by editing ~/.bashrc or /etc/profile:
export JAVA_HOME=/usr/local/java/jdk-25
export PATH=$JAVA_HOME/bin:$PATH
- Apply the configuration:
source ~/.bashrc
- 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
- Download the macOS version of JDK (dmg file)
- Open the downloaded dmg file
- Drag JDK to the Applications folder
- Open terminal and configure environment variables:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
- Add the above to ~/.zshrc or ~/.bash_profile
- 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
- Configure MAVEN_HOME or GRADLE_HOME if using Maven or Gradle
- Configure M2_HOME for Maven local repository path
- Configure HTTP proxy if needed in enterprise environments
- Set timezone to ensure correct time for Java applications
Uninstalling Java
Windows Control Panel
- Open Control Panel
- Select "Programs and Features"
- Find Java-related programs
- 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-*
