Download and Install Java
What Do You Need to Install?
To write and run Java programs you need the Java Development Kit (JDK). It includes:
- javac — the Java compiler that turns your source code into bytecode
- java — the JVM launcher that runs bytecode
- jar, javadoc — packaging and documentation tools
- JRE — the runtime environment (bundled inside the JDK)
💡 Which version? Always prefer a Long Term Support (LTS) release for stability. The current LTS versions are Java 17 and Java 21. Java 21 is recommended for new projects.
LTS Version Overview
| Version | Type | Release Date | Support Until | Recommendation |
|---|---|---|---|---|
| Java 8 | LTS | Mar 2014 | Dec 2030 | Legacy projects only |
| Java 11 | LTS | Sep 2018 | Sep 2026 | Still widely used |
| Java 17 | LTS | Sep 2021 | Sep 2029 | Stable choice |
| Java 21 | LTS | Sep 2023 | Sep 2031 | ✅ Recommended |
Installation Guide
Install on Windows
Go to Oracle JDK downloads or Adoptium (OpenJDK). Choose Windows x64 Installer (.msi) for Java 21.
Double-click the downloaded
.msi file. Click
Next through the wizard and accept the default
install path:
C:\Program Files\Java\jdk-21
- Open Start ? search Environment Variables ? click Edit the system environment variables.
- Click Environment Variables button.
-
Under System variables click
New:
-
Variable name:
JAVA_HOME -
Variable value:
C:\Program Files\Java\jdk-21
-
Variable name:
-
Find the
Pathvariable ? click Edit ? click New ? add:%JAVA_HOME%\bin - Click OK on all dialogs.
Open Command Prompt and run:
java -version javac -version
Expected output:
Install on macOS
Option A — Using Homebrew (Recommended)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install openjdk@21
sudo ln -sfn $(brew --prefix openjdk@21)/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk echo 'export JAVA_HOME=$(brew --prefix openjdk@21)' >> ~/.zshrc source ~/.zshrc
Option B — Manual .pkg Installer
.pkg from Oracle or Adoptium for
Java 21.
.pkg and follow the installer
wizard.
echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 21)' >> ~/.zshrc source ~/.zshrc
java -version javac -version
Install on Linux
Ubuntu / Debian
sudo apt update sudo apt install openjdk-21-jdk -y
echo 'export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64' >> ~/.bashrc echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc source ~/.bashrc
Fedora / RHEL / CentOS
sudo dnf install java-21-openjdk-devel -y
Arch Linux
sudo pacman -S jdk21-openjdk
java -version javac -version
Verify Your Installation
Open a terminal (or Command Prompt on Windows) and run these two commands:
java -version javac -version
Both commands must return a version number. If you get
"command not found" or "not recognized", the
PATH is not set correctly — revisit Step
3 of your OS section above.
⚠️ Common mistake: Installing JRE
instead of JDK. The JRE does not include
javac. Make sure you downloaded the
JDK.
Write and Run Your First Program
Once Java is installed, confirm everything works end-to-end:
HelloWorld.java
with this content:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Java is installed and working!");
}
}
javac HelloWorld.java
This creates a HelloWorld.class file
in the same folder.
java HelloWorld
✅ You're all set! Java is correctly installed and your first program ran successfully.
Oracle JDK vs OpenJDK
| Feature | Oracle JDK | OpenJDK (Adoptium / Amazon Corretto) |
|---|---|---|
| License | Free for dev/testing; paid for production | 100% free and open source |
| Performance | Identical | Identical |
| Long-term support | Yes (Oracle subscription) | Yes (community / vendor) |
| Recommended for | Oracle-supported enterprise environments | Most developers and projects |
📌 For personal learning and most professional projects, OpenJDK from Adoptium (Eclipse Temurin) is the best choice — fully free with LTS support.
Managing Multiple Java Versions
If you need to switch between Java versions (e.g. Java 11 for an old project and Java 21 for a new one), use a version manager:
-
SDKMAN (macOS / Linux) —
sdk install java 21-temthensdk use java 21-tem - Jabba (Windows / macOS / Linux) — cross-platform JDK version manager
-
Windows: manually update
JAVA_HOMEto point to the desired version folder
# SDKMAN example (macOS/Linux) sdk list java # see available versions sdk install java 21-tem sdk install java 17-tem sdk use java 17-tem # switch for current session sdk default java 21-tem # set global default
