Skip to lesson

Install Java (JDK) on your computer

I'm on:

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, and it is free. Get it from Oracle, or from Eclipse Temurin, a free open-source JDK that works the same way.

Choose the latest version marked LTS (Long-Term Support): it gets fixes for many years. We recommend JDK 25; JDK 21 works too. Course examples run on Java 17 and newer.

On Windows

Under the LTS version, click the Windows tab. Most Windows computers use an x64 processor.

  • x64 Installer – the .exe file. Choose this one.
  • x64 MSI Installer – the .msi file. It installs the same JDK, so it is also fine.
  • Skip the x64 Compressed Archive (.zip). It needs manual setup.
This course gives steps for Windows and macOS only. Linux is not covered step by step in this version: use your distribution's OpenJDK package (for example openjdk-25-jdk on Ubuntu) or Temurin, then check with java -version.

Install the JDK

Run the file you downloaded and follow the steps for your computer. Each JDK goes into its own folder, named by its maker, 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.

  1. Open your Downloads folder and double-click the .exe (or .msi) file.
  2. If Windows asks "Do you want to allow this app to make changes to your device?", click Yes.
  3. Click Next. Keep the default folder and note its name: an IDE may ask for it later.
  4. Wait for the install to finish, then click Close.
Using Temurin? In its installer, keep Add to PATH selected (it is on by default).

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.

  1. Press the Windows key, type cmd and press Enter.
  2. Type java -version and press Enter.
  3. Type javac -version and press Enter.
  4. Both should show a version number, for example javac 25.0.1. Your number may be different.
Success checkpoint: 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.

Picture 1 / 4
You type javac. The computer looks for it in the first folder listed in PATH.
Picture 1 / 4

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.

  1. In File Explorer, find your JDK's bin folder, for example C:\Program Files\Java\jdk-25\bin. Copy the address from the top bar.
  2. Press the Windows key, type environment variables and open Edit the system environment variables. Click Environment Variables….
  3. Under System variables, select Path and click Edit.
  4. Click New and paste the bin address. If an older Java folder is above it, click Move Up until yours is above the old one.
  5. Click OK in all three windows. Open a new Command Prompt and run where javac and javac -version again.
If 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

Terminal
java -versionjavac -version
Sample output
java 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 -version shows the Java version that runs programs. javac -version shows 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

Practice what you learned

3 small exercises