Java course menu
Installing Java (JDK) on Windows, macOS and Linux
Install the Java Development Kit (JDK) step by step: choosing a JDK distribution and version, installing on Windows with winget or an installer, on macOS with Homebrew, and on Linux with apt; checking java and javac, setting JAVA_HOME, and choosing an editor.
On this page
To write Java programs you need the JDK (Java Development Kit). It contains the javac compiler, the java launcher that runs programs, and the standard libraries.
Which JDK should I install?#
Java is open source (OpenJDK), and several organizations publish free, production-ready builds of it, such as Microsoft Build of OpenJDK, Eclipse Temurin (Adoptium), Amazon Corretto and Oracle OpenJDK. They are built from the same source code and behave the same for learning.
Install a long-term support (LTS) version: Java 21 (used in this course) or a newer LTS such as Java 25.
Windows#
Option 1: winget (quick)#
Open PowerShell and run:
winget install Microsoft.OpenJDK.21The installer asks for administrator permission and sets up PATH for you. Close and reopen PowerShell, then check both tools:
java --version
javac --versionYou should see version 21 (or newer) for both.
Option 2: download an installer#
Download a .msi installer for Windows x64 from the JDK provider's website (for example Microsoft Build of OpenJDK or Eclipse Temurin), run it, and make sure the option to add Java to PATH (and set JAVA_HOME) is selected.
macOS#
With Homebrew:
brew install openjdk@21Homebrew prints a command to link the JDK so the system finds it; run that command, then check with java --version. Alternatively, download a .pkg installer from a JDK provider.
Linux#
On Ubuntu or Debian:
sudo apt update
sudo apt install openjdk-21-jdk
java --version
javac --versionOn Fedora, use sudo dnf install java-21-openjdk-devel.
Run a test program#
Create a file named Hello.java. The file name must match the public class name, including capital letters:
public class Hello {
public static void main(String[] args) {
System.out.println("Java is installed!");
}
}Java is installed!There are two ways to run it from a terminal in the same folder.
Compile, then run (the classic way, and what larger projects do):
javac Hello.java
java Hellojavac creates Hello.class; java Hello runs that class (no .class extension).
Run the source file directly (Java 11 and later, handy for single-file programs):
java Hello.javaJAVA_HOME#
Many tools (Maven, Gradle, IDEs) look for an environment variable called JAVA_HOME that points to the JDK folder, such as C:\Program Files\Microsoft\jdk-21... on Windows or /usr/lib/jvm/java-21-openjdk-amd64 on Linux. Installers usually set it; if a tool says it cannot find Java, set JAVA_HOME to the JDK folder (the one containing bin).
Choosing an editor#
- IntelliJ IDEA Community Edition: free, the most popular Java IDE, with excellent code completion and refactoring.
- Visual Studio Code with the Extension Pack for Java: lightweight and works well for learning.
- Eclipse and NetBeans: free, long-established IDEs.
An IDE compiles and runs your program with one click, but knowing the javac and java commands helps you understand what happens underneath.
Common problems#
Key takeaway#
Next: write and understand your First Java Program.
Finished this lesson?