Install OpenJDK on Linux, macOS and Windows (Java 25)

Install OpenJDK 25 on Linux, macOS and Windows with apt, dnf, Homebrew, winget or SDKMAN. Pick a build, set JAVA_HOME and verify java -version.

Decision chart for installing OpenJDK 25 with apt, dnf, Homebrew, winget, SDKMAN or a manual archive

To install OpenJDK, we install a free build of it, such as Eclipse Temurin, Amazon Corretto or the package of our Linux distribution, with the package manager of the operating system, and check the result with java -version. The commands differ per system, namely apt or dnf on Linux, Homebrew on macOS, winget on Windows, and SDKMAN on all three.

We need a JDK to compile and run Java code, to build projects with Maven or Gradle, and to run tools such as IDEs that look for JAVA_HOME. The current long-term support (LTS) version is Java 25, released in September 2025, so that is the version we install here.

The following example installs OpenJDK 25 with one command per system.

sudo apt install openjdk-25-jdk                  # Ubuntu 22.04, 24.04 and 26.04, Debian-based distros
sudo dnf install java-25-openjdk-devel           # Fedora 43 and later
brew install --cask temurin@25                   # macOS with Homebrew
winget install EclipseAdoptium.Temurin.25.JDK    # Windows 10 and 11
sdk install java 25.0.3.0+9-tem                  # any system with SDKMAN (pick the version from "sdk list java")
java -version                                    # openjdk version "25.0.x" ... LTS

Every command installs a full JDK with javac, not only a runtime. We first pick a build, walk through Linux, macOS and Windows in detail, set JAVA_HOME, switch between several versions, and verify the setup.

1. Which OpenJDK Build to Install

OpenJDK is the open-source project that develops Java, and it publishes source code, not installers. Several vendors compile that code, test it and ship ready-made builds, which are functionally the same Java with different support periods and packaging. The difference between the JDK, JRE and JVM matters here, because only the JDK contains javac.

Decision chart for installing OpenJDK 25 with apt, dnf, Homebrew, winget, SDKMAN or a manual archive
Pick the package manager of your system, and fall back to SDKMAN or the archive when you need several versions or no admin rights
BuildVendorCost and licenseGood for
Eclipse TemurinEclipse AdoptiumFree, GPLv2 with Classpath ExceptionDefault choice on every system
Amazon CorrettoAmazonFree, GPLv2 with Classpath ExceptionApps that run on AWS
Microsoft Build of OpenJDKMicrosoftFree, LTS versions onlyApps that run on Azure
Distro packages (openjdk-25-jdk, java-25-openjdk)Ubuntu, Debian, Fedora, Red HatFree, updated with the OSLinux servers
Oracle OpenJDK buildsOracleFree, updates only until the next releaseTrying the newest version
Oracle JDKOracleFree under the NFTC license, JDK 25 updates until September 2028Teams that want the Oracle build

Say a team of six developers starts a new Spring Boot service. Everyone installs Temurin 25 with their system’s package manager, and the CI pipeline and the Docker base image use Temurin 25 too, so a bug never depends on whose laptop ran the build. Mixing a Temurin laptop with a Corretto server works too, because both pass the same compatibility tests, but one build everywhere keeps support questions short.

Java 26 (March 2026) and Java 27 (September 2026) are newer feature releases. They get updates for six months each, so we install them to try new features and stay on Java 25 for production.

2. Installing OpenJDK on Linux

On Linux, the distribution package is the fastest route, because the OS update tool keeps Java patched with everything else. On Ubuntu and Debian-based systems, the package is openjdk-25-jdk, and Ubuntu ships it for 22.04, 24.04 and 26.04.

sudo apt update
sudo apt install openjdk-25-jdk
readlink -f "$(which java)"       # /usr/lib/jvm/java-25-openjdk-amd64/bin/java

On Fedora, the JDK with javac is the -devel package, whereas java-25-openjdk alone contains only the runtime.

sudo dnf install java-25-openjdk-devel

When we want Temurin instead of the distro build, for example to match the Docker image, we add the Adoptium repository once and install temurin-25-jdk.

sudo apt install -y wget apt-transport-https gpg
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null
echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
sudo apt update
sudo apt install temurin-25-jdk

2.1. Installing From a tar.gz Archive

Without root access, or on a distribution without a package, we download the tar.gz archive of the build and unpack it. The archive contains a single folder, such as jdk-25.0.4.1+1 for Temurin, and nothing else needs to be installed.

sudo tar -xzf OpenJDK25U-jdk_x64_linux_hotspot_25.0.4.1_1.tar.gz -C /opt
echo 'export JAVA_HOME=/opt/jdk-25.0.4.1+1' >> ~/.bashrc
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

A user without sudo unpacks the archive into a folder in the home directory, such as ~/jdks, with the same two exports. The single quotes keep $JAVA_HOME and $PATH unexpanded in .bashrc, so they are resolved each time a shell starts.

2.2. Switching Between Installed Versions

Packages from apt and dnf register themselves with the alternatives system, which decides what /usr/bin/java points to. With several JDKs installed, we pick the default interactively.

sudo update-alternatives --config java
sudo update-alternatives --config javac

3. Installing OpenJDK on macOS

On macOS, every JDK lives in its own folder under /Library/Java/JavaVirtualMachines, and the /usr/bin/java launcher picks one from there. Homebrew installs Temurin into that folder with one command.

brew install --cask temurin@25
/usr/libexec/java_home -V          # lists every installed JDK and its folder

Homebrew also has an openjdk@25 formula, which installs under the Homebrew prefix instead. The system launcher does not see it until we link it into /Library/Java/JavaVirtualMachines with the command that Homebrew prints after the install.

brew install openjdk@25
sudo ln -sfn "$(brew --prefix)/opt/openjdk@25/libexec/openjdk.jdk" /Library/Java/JavaVirtualMachines/openjdk-25.jdk

Without Homebrew, we download the .pkg installer of Temurin or Corretto and double-click it, which puts the JDK in the same folder. To set JAVA_HOME for tools such as Maven, we add one line to ~/.zshrc, the default shell profile on macOS.

echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 25)' >> ~/.zshrc
source ~/.zshrc

4. Installing OpenJDK on Windows

On Windows 10 and 11, the winget package manager installs the Temurin MSI without opening a browser. The installer adds the JDK to the PATH, but it does not set JAVA_HOME unless we ask for it.

winget install EclipseAdoptium.Temurin.25.JDK
winget search openjdk                 # Corretto, Microsoft and other builds

When we run the downloaded MSI by hand, the “Set JAVA_HOME variable” feature in the Custom Setup screen is switched off by default, so we turn it on there. To set the variable later, we run the following PowerShell commands, which find the JDK 25 folder that the installer created under C:\Program Files\Eclipse Adoptium, and open a new terminal afterwards.

$jdk = (Get-ChildItem "C:\Program Files\Eclipse Adoptium" -Directory -Filter "jdk-25*").FullName
[Environment]::SetEnvironmentVariable("JAVA_HOME", $jdk, "User")

Avoid setx PATH “%PATH%;…”, because setx cuts values longer than 1,024 characters and can damage a long PATH. For the ZIP archive and the full walkthrough of the Environment Variables dialog, see how to install Java on 64-bit Windows, and setting environment variables without admin access on locked-down company laptops.

5. Installing OpenJDK With SDKMAN

SDKMAN is a version manager for Linux, macOS and Windows through WSL or Git Bash. It installs JDKs into the home folder, sets JAVA_HOME and switches versions per terminal, which helps developers who maintain apps on Java 17, 21 and 25 at the same time.

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk list java                        # every vendor and version, e.g. 25.0.3.0+9-tem
sdk install java 25.0.3.0+9-tem      # Temurin 25
sdk install java 21.0.12+1.1-tem     # Temurin 21 next to it
sdk use java 21.0.12+1.1-tem         # this terminal only
sdk default java 25.0.3.0+9-tem      # all new terminals

The identifiers change with every update, so we copy them from sdk list java on the day. A .sdkmanrc file in a project, created with sdk env init, pins the JDK version for everyone who opens that project.

6. Verifying the Installation

Two commands confirm the install, one for the runtime and one for the compiler. Both must report the same version, otherwise PATH points to two different JDKs.

java -version
javac -version
openjdk version "25.0.4.1" 2026-08-18 LTS
OpenJDK Runtime Environment Temurin-25.0.4.1+1 (build 25.0.4.1+1-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.4.1+1 (build 25.0.4.1+1-LTS, mixed mode, sharing)
javac 25.0.4.1

Inside an app, the same information is available from system properties and Runtime.version(), which helps when a support ticket asks which Java the server runs.

String version = System.getProperty("java.version");       // "25.0.4.1"
int feature = Runtime.version().feature();                 // 25
String vendor = System.getProperty("java.vendor");         // "Eclipse Adoptium"

If java -version prints an older version, an earlier JDK comes first in the PATH. On Linux and macOS, which -a java lists every match in order, and on Windows, where java does the same.

7. OpenJDK Installation FAQs

Each of these questions is typical right before or right after the first java -version on a new machine.

7.1. Is OpenJDK free for commercial use?

Yes. OpenJDK is licensed under GPLv2 with the Classpath Exception, so builds such as Temurin, Corretto and the distro packages are free for development and production. Only Oracle JDK has its own license terms, which are free under the NFTC license for JDK 25 updates until September 2028.

7.2. What is the difference between OpenJDK and Oracle JDK?

Both are built from the same OpenJDK source code and pass the same compatibility tests. The differences are the license, the support period and the vendor that ships the updates.

7.3. Can I install only the JRE?

Oracle has not shipped a separate JRE since Java 11, but some vendors still publish one, such as temurin-25-jre and the openjdk-25-jre package on Ubuntu. A JRE runs apps but cannot compile them, so developers always install the JDK. For containers, a jlink runtime with only the needed modules is smaller still.

7.4. Can I have several Java versions installed at once?

Yes. Each JDK goes into its own folder, and the active one is decided by PATH and JAVA_HOME. We switch with update-alternatives on Linux, /usr/libexec/java_home -v on macOS, the environment variables on Windows, or sdk use with SDKMAN.

7.5. How do I uninstall OpenJDK?

We use the same tool that installed it, such as sudo apt remove openjdk-25-jdk, brew uninstall –cask temurin@25, winget uninstall EclipseAdoptium.Temurin.25.JDK or sdk uninstall java 25.0.3.0+9-tem. An archive install is removed by deleting its folder and the JAVA_HOME lines in the shell profile.

8. Conclusion

Installing OpenJDK 25 takes one package manager command on each system, which is apt or dnf on Linux, Homebrew on macOS and winget on Windows. SDKMAN covers developers who need several versions side by side, and the tar.gz or ZIP archive works without admin rights.

Temurin is a safe default, while Corretto, the Microsoft build and the distro packages are equally valid OpenJDK builds. After the install, java -version and javac -version must show the same version, and JAVA_HOME must point to the JDK folder for build tools. The Java tutorial is a good next step.

9. References

Happy Learning !!

Source Code on Github

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.