Install the JDK & Set Up

Java · Lesson 2 of 32 8 min read Updated

Before you can write Java, you need a JDK (Java Development Kit) on your computer. In this lesson you will install Java 25 LTS, make sure your terminal can find it, try out Java's interactive shell, and choose an editor.

The whole process takes about ten minutes. Most problems beginners face later ("javac is not recognized", "wrong version") come from a messy setup, so it is worth doing carefully once.

Choose a JDK build

Java's source code lives in the open-source OpenJDK project. Several companies build installers from that same code. They behave the same way for learning, so pick one and move on.

BuildFromNotes
Eclipse TemurinAdoptium (Eclipse Foundation)Free, popular, easy installers. Used in this lesson.
Oracle JDKOracleOfficial Oracle build; read its licence if you use it at work.
Amazon CorrettoAmazonFree, used on AWS.
Microsoft Build of OpenJDKMicrosoftFree, used on Azure.

Always choose version 25 (the current LTS) and the JDK, not a JRE.

Install on Windows

The simplest way is the official MSI installer from adoptium.net. Choose Windows, x64 (or aarch64 for ARM laptops), JDK, version 25, and download the .msi file. While installing:

  • Keep Add to PATH switched on (it is on by default).
  • Switch on Set JAVA\_HOME variable. It is off by default, and build tools such as Maven look for it.

If you prefer the command line, Windows 10 and 11 include the winget package manager. Open PowerShell and run:

PowerShell
winget install EclipseAdoptium.Temurin.25.JDK

Close and reopen your terminal after installing, so it picks up the new PATH.

Install on macOS and Linux

On macOS you can use the .pkg installer from adoptium.net, or Homebrew:

Terminal
brew install --cask temurin@25

On Ubuntu 26.04 LTS, Java 25 is the default JDK, so either command below works. On other distributions, use your package manager or the packages listed on adoptium.net.

Terminal
sudo apt update
sudo apt install openjdk-25-jdk

Check your installation

Open a new terminal and ask both the runtime and the compiler for their versions:

Terminal
java -version
javac -version

You should see a version starting with 25. The exact update number and date change every three months, so yours may differ. In October 2026 the Temurin output looks like this:

Text
openjdk version "25.0.5" 2026-10-20 LTS
OpenJDK Runtime Environment Temurin-25.0.5+8 (build 25.0.5+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.5+8 (build 25.0.5+8-LTS, mixed mode, sharing)
javac 25.0.5

If javac prints "not recognized" or "command not found", the JDK's bin folder is not on your PATH. If java -version shows an old version such as 1.8.0, an older Java is earlier on your PATH.

JAVA_HOME and PATH explained

Two environment variables matter:

  • PATH is the list of folders your terminal searches when you type a command. The JDK's bin folder (which holds java.exe and javac.exe) must be in it.
  • JAVA\_HOME points to the JDK folder itself (the parent of bin). Maven, Gradle and many IDEs read it to find Java.

On Windows, this PowerShell snippet shows both and lists every java.exe the system can find. The first one listed is the one that runs.

PowerShell
$env:JAVA_HOME
where.exe java

On a laptop that once had Oracle Java 8, the output might look like this:

Text
C:\Program Files\Eclipse Adoptium\jdk-25.0.5.8-hotspot\
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Eclipse Adoptium\jdk-25.0.5.8-hotspot\bin\java.exe

Here the old Oracle javapath folder comes first, so typing java runs Java 8. Fix it by uninstalling the old Java from Settings > Apps, or by moving the JDK 25 bin entry above it in System Properties > Environment Variables > Path. Then open a new terminal and check again.

Try Java instantly with JShell

The JDK includes JShell, an interactive shell (a REPL: read, evaluate, print, loop). You type a line of Java and see the result at once, without writing a class or compiling. It is perfect for testing small ideas. Start it by typing jshell, and leave with /exit.

Text
jshell> 7 * 24
$1 ==> 168

jshell> String city = "Kochi"
city ==> "Kochi"

jshell> city.length()
$3 ==> 5

jshell> city.toUpperCase()
$4 ==> "KOCHI"

JShell stores each result in a variable such as $1, so you can reuse it. You will use JShell throughout this course to check small facts quickly.

Choose an editor

You can write Java in any text editor, but a Java-aware editor underlines mistakes as you type, completes method names and runs programs with one click.

  • IntelliJ IDEA from JetBrains: the most popular Java IDE, with a free edition that covers this whole course.
  • VS Code with Microsoft's Extension Pack for Java: lighter, good if you already use VS Code.
  • Eclipse IDE: free and open source, still common in colleges and companies.

For the first few lessons, use the terminal and a plain editor. Typing javac and java yourself teaches you what an IDE does behind the scenes.

Common mistakes

  • Not reopening the terminal. A terminal keeps the PATH it had when it opened. After installing, always open a new one.
  • Two Java versions fighting. Use where.exe java (Windows) or which -a java (Linux, macOS) to see every copy and which one wins.
  • JAVA\_HOME pointing at bin. It must point to the JDK folder, such as C:\Program Files\Eclipse Adoptium\jdk-25.0.5.8-hotspot, not to its bin subfolder.
  • Installing a JRE by mistake. If java -version works but javac does not exist, you installed a runtime only. Install the JDK.

Key points

  • Install a JDK for Java 25 LTS; Eclipse Temurin, Oracle, Amazon and Microsoft builds all come from OpenJDK.
  • On Windows use the MSI (switch on "Set JAVA\_HOME variable") or winget install EclipseAdoptium.Temurin.25.JDK.
  • Check with java -version and javac -version; both should start with 25.
  • PATH must contain the JDK's bin folder; JAVA\_HOME must point to the JDK folder.
  • JShell lets you run single lines of Java instantly.

Exercise

Install JDK 25, then:

  1. Run java -version and javac -version and note the update number.
  2. Run where.exe java (Windows) or which -a java (macOS/Linux). How many copies of Java do you have?
  3. Start JShell and work out how many minutes there are in a week. Then store your city in a variable and print it in capital letters.
Show solution

Both version commands should start with 25. If more than one Java is listed in step 2, make sure the JDK 25 entry is first. In JShell:

Text
jshell> 7 * 24 * 60
$1 ==> 10080

jshell> String city = "Pune"
city ==> "Pune"

jshell> city.toUpperCase()
$3 ==> "PUNE"

A week has 10,080 minutes. JShell prints each result straight away, so you do not need System.out.println here.

Quick Quiz

1. Which variable should point to the JDK folder (not its bin folder)?

2. java -version prints 1.8.0_401 even though you installed JDK 25. What is the most likely cause?

3. What is JShell?

4. Which MSI option is switched off by default in the Temurin installer?

Learn Java with a mentor

Free lessons get you started. Our Java, C & C++ Programming training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call