Java Installation
The Java Development Kit (JDK) provides the tools needed to develop Java applications. This guide covers installation on different operating systems.
Choosing a JDK
Section titled “Choosing a JDK”There are several JDK distributions available:
- Oracle JDK: Official Oracle implementation (requires license for commercial use)
- OpenJDK: Free, open-source implementation
- AdoptOpenJDK/Eclipse Temurin: Community-maintained, production-ready OpenJDK builds
For beginners, Eclipse Temurin (formerly AdoptOpenJDK) is recommended due to its ease of installation and long-term support.
Windows
Section titled “Windows”Using the installer
Section titled “Using the installer”- Download the JDK installer from Eclipse Temurin
- Run the installer and follow the installation wizard
- The installer will set the
JAVA_HOMEenvironment variable automatically - Verify installation by opening Command Prompt and typing:
java -version
Manual environment variable setup (if needed)
Section titled “Manual environment variable setup (if needed)”- Right-click on “This PC” or “My Computer” and select “Properties”
- Click on “Advanced system settings”
- Click the “Environment Variables” button
- Under System Variables, click “New” and add:
- Variable name:
JAVA_HOME - Variable value: Your JDK installation path (e.g.,
C:\Program Files\Java\jdk-17)
- Variable name:
- Edit the “Path” variable and add
%JAVA_HOME%\bin
Using Homebrew
Section titled “Using Homebrew”- Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- Install OpenJDK:
brew install --cask temurin
- Verify installation:
java -version
Using the installer
Section titled “Using the installer”- Download the macOS
.pkgfile from Eclipse Temurin - Open the downloaded file and follow the installation instructions
- Verify installation by opening Terminal and typing:
java -version
Debian/Ubuntu
Section titled “Debian/Ubuntu”sudo apt updatesudo apt install openjdk-17-jdkFedora/RHEL
Section titled “Fedora/RHEL”sudo dnf install java-17-openjdk-develVerify installation
Section titled “Verify installation”java -versionMultiple Java Versions
Section titled “Multiple Java Versions”If you need multiple Java versions, consider using a version manager:
- Windows: SDKMAN for Windows (via WSL)
- macOS/Linux: SDKMAN
With SDKMAN, you can install and switch between Java versions:
sdk install java 17.0.2-temsdk use java 17.0.2-temVerifying Your Installation
Section titled “Verifying Your Installation”Create a simple Hello World program to test your installation:
- Create a file named
HelloWorld.javawith the following content:public class HelloWorld {public static void main(String[] args) {System.out.println("Hello, Java!");}} - Compile the program:
javac HelloWorld.java
- Run the program:
java HelloWorld
If you see “Hello, Java!” printed in the console, your Java installation is working correctly.