Install Java (JDK) on your computer
20 min · Beginner
Showing steps for Windows. They are marked “On Windows” below.
To write Java programs, you need the JDK on your computer. Download it from an official site, install it, then check that java and javac work.
Choose the right JDK file
The JDK (Java Development Kit) has the compiler javac and the JVM. It is free. Open the Oracle JDK downloads page using the button below. Eclipse Temurin is a free, open-source JDK that works the same way.
The page shows more than one Java version. Choose the latest one marked LTS (Long-Term Support). An LTS version gets fixes for many years. We recommend JDK 25; JDK 21 (also LTS) works too.
The course examples are written to work on Java 17 and newer, and we test them on recent JDKs. Now pick the file for your computer.
Official downloads
On Windows
Under the LTS version, click the Windows tab. Most Windows computers use an x64 processor.
- x64 Installer – the
.exefile. Choose this one. - x64 MSI Installer – the
.msifile. It installs the same JDK, so it is also fine. - Skip the x64 Compressed Archive (
.zip). It needs manual setup.
openjdk-25-jdk on Ubuntu) or Temurin, then check with java -version.Install the JDK
Now run the file you downloaded. Follow the steps for your computer. Each JDK goes into its own folder, and the folder name depends on who made it, so the folders below are only examples.
On Windows
Oracle's installer uses a folder like C:\Program Files\Java\jdk-25. Temurin uses a folder inside C:\Program Files\Eclipse Adoptium, with the full version in its name.
- Open your Downloads folder and double-click the
.exe(or.msi) file. - If Windows asks "Do you want to allow this app to make changes to your device?", click Yes.
- Click Next. Keep the default folder and note its name: an IDE may ask for it later.
- Wait for the install to finish, then click Close.
Check that Java works
Now check the install from the command line. Always open a new window after you install, so it can find the new JDK.
On Windows
Use Command Prompt or PowerShell. Both work the same for these commands.
- Press the Windows key, type
cmdand press Enter. - Type
java -versionand press Enter. - Type
javac -versionand press Enter. - Both should show a version number, for example
javac 25.0.1. Your number may be different.
java -version works, javac -version works, and both show the same main version (for example 25). The last check, running Hello World, comes in Your first Java program.Fix common problems
Your computer finds commands by looking in a list of folders called PATH. If no folder in PATH has javac, the command is not found.
First, close the window, open a new one and try again. If it still fails, follow the steps for your computer.
On Windows
Check first, then change PATH only if needed. In a new Command Prompt, type where java and where javac. Each shows the folders where Windows finds that command; the first line is the one it uses. With Oracle's installer, the first line may be in C:\Program Files\Common Files\Oracle\Java\javapath. That is normal.
Change PATH only if you see 'javac' is not recognized, or if the first line belongs to an older Java.
- In File Explorer, find your JDK's
binfolder, for exampleC:\Program Files\Java\jdk-25\bin. Copy the address from the top bar. - Press the Windows key, type
environment variablesand open Edit the system environment variables. Click Environment Variables…. - Under System variables, select Path and click Edit.
- Click New and paste the
binaddress. If an older Java folder is above it, click Move Up until yours is above the old one. - Click OK in all three windows. Open a new Command Prompt and run
where javacandjavac -versionagain.
java -version shows an old version (like 1.8), where java will show the old folder first. Moving your new bin folder above it fixes this.Example
java -versionjavac -versionjava version "25.0.x" 20xx-xx-xx LTS Java(TM) SE Runtime Environment (build 25.0.x+...) Java HotSpot(TM) 64-Bit Server VM (build 25.0.x+..., mixed mode, sharing) javac 25.0.x
What this code does
- Type each command in Command Prompt (Windows) or Terminal (macOS), then press Enter.
java -versionshows the Java version that runs programs.javac -versionshows the compiler version.- This is sample output from Oracle's JDK. Your numbers and dates will differ, and Temurin starts with
openjdk version. That is fine, as long as you see a version and no error.
Next step
Check your understanding
6 quick questions