How to Install Java (OpenJDK) on Linux: Ubuntu, AlmaLinux and JAVA_HOME

install java linux - custom-javainst-featured.png

Install Java on Linux backs Tomcat, Jenkins, Elasticsearch, Kafka, Minecraft servers, and countless enterprise apps. On servers you usually want OpenJDK from distro repos or a vendor build — then set JAVA_HOME so services find the same JDK.

CI: Jenkins on Linux. Compare runtimes with
Node.js install for polyglot stacks.

JDK vs JRE vs Headless

Servers often need only -headless packages without GUI libraries.

OpenJDK
packages

Ubuntu / Debian Install

LTS releases ship OpenJDK 17 or 21 in main repos.

bashUbuntu
sudo apt update
sudo apt install -y openjdk-17-jdk
java -version
javac -version
apt install
version

AlmaLinux / Rocky Install

AppStream provides multiple Java streams.

bashAlmaLinux
sudo dnf install -y java-17-openjdk java-17-openjdk-devel
java -version
dnf install
java-17

Set JAVA_HOME

Apps and Tomcat startup scripts expect JAVA_HOME pointing at the JDK root.

bashsystem-wide
echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' | sudo tee /etc/profile.d/java.sh
profile.d
export

Multiple Versions

Use update-alternatives on Debian or alternatives on RHEL to switch default java.

bashDebian
sudo update-alternatives --config java
alternatives
switch

Headless on Minimal Servers

Smaller footprint for containers and CI runners.

bashUbuntu headless
sudo apt install -y openjdk-17-jre-headless
headless pkg
servers

Verify for Your App

Run the same user systemd uses; check echo $JAVA_HOME in that context.

verify
javac

Quick Reference

  • Servers: openjdk-*-jdk or -jre-headless
  • Set JAVA_HOME in /etc/profile.d/
  • Multiple JDKs: update-alternatives

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.