Install Java on OpenBSD

Introduction

OpenBSD packages OpenJDK for the current release. The package name carries the major version, so installing a specific release is explicit.

Install a JDK

doas pkg_add jdk-17

Without doas configured, run the same command as root. The JDK lands under /usr/local/jdk-17.

JAVA_HOME

Point build tools at the JDK:

export JAVA_HOME=/usr/local/jdk-17

Add the line to ~/.profile to keep it across logins.

Check the version

java -version

Both java and javac must report the installed release.

Which JDK flavor

OpenBSD packages the standard OpenJDK; there is no Oracle binary to compare with, which simplifies the choice to the major version your project targets. Match production exactly — «works on my Linux, fails on OpenBSD» almost always means different JDK builds, not different code.

Banner image