How to Install Java on Linux Distributions: Fast, Step-by-Step Guide for All Distros
Want to install Java on Linux without the guesswork? This fast, step-by-step guide walks you through choosing JRE vs JDK, distro-specific commands, and best practices to keep your servers secure and up to date.
Introduction
Java remains one of the most widely used runtime platforms for web applications, backend services, build tooling and automation. For server administrators, developers and site owners running applications on Linux-based VPS instances, quickly and reliably installing Java is a frequent operational task. This guide provides a fast, step-by-step walkthrough to install and manage Java across major Linux distributions, explains the underlying concepts, compares options, and offers practical recommendations for production deployments.
Understanding Java on Linux: JRE vs JDK and Distribution Choices
Before installation, it’s important to understand the components and distribution options:
- JRE (Java Runtime Environment) — needed to run Java applications (java command).
- JDK (Java Development Kit) — includes JRE plus compiler (javac), tools and headers required to build Java apps.
- OpenJDK — the open-source reference implementation used by most Linux packages.
- Oracle JDK — Oracle’s distribution; historically included commercial licensing. Most server deployments favor OpenJDK or vendor builds like Eclipse Temurin or Amazon Corretto for ease of updates and licensing.
Choosing the right distribution usually comes down to supported versions (8, 11, 17, 21, etc.), vendor updates/patches, licensing and package management convenience.
Quick Principles: What the Installer Does and System Considerations
When you install Java via package managers or manually:
- Packages place binaries (java, javac) under
/usr/bin(or create symlinks), and libraries under/usr/lib/jvmor equivalent. - Multiple Java installations can coexist; Linux uses
update-alternatives(Debian/Ubuntu) or manual symlinks to set the default java executable. - JAVA_HOME environment variable is required by many frameworks and build tools; it should point to the JDK root (e.g.
/usr/lib/jvm/java-11-openjdk-amd64). - Keep security updates in mind—prefer vendor packages that integrate with your distro’s package manager to apply patches via standard OS updates.
Step-by-step Installations by Distribution
Debian / Ubuntu (apt)
Install OpenJDK via apt for a quick, supported setup.
- Update packages:
sudo apt update - Install JDK 17 (example):
sudo apt install -y openjdk-17-jdk - Verify:
java -versionandjavac -version - If multiple versions present, manage default with:
sudo update-alternatives --config javaand similarly for javac. - Set JAVA_HOME globally in
/etc/profile.d/java.sh(example):export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
RHEL / CentOS 7 & 8 / AlmaLinux / Rocky Linux (yum / dnf)
On RHEL-family, use yum or dnf and enable appropriate repositories.
- Install OpenJDK 11:
sudo yum install -y java-11-openjdk-devel(orsudo dnf install -y java-11-openjdk-develon newer releases). - Verify:
java -version - To set default: use
sudo alternatives --config java(RHEL uses alternatives similar to Debian’s update-alternatives). - For vendor builds like Amazon Corretto or Eclipse Temurin, follow vendor RPM repository instructions and then install via yum/dnf for easy updates.
Fedora (dnf)
- Install with:
sudo dnf install -y java-17-openjdk-devel - Manage alternatives with:
sudo alternatives --config java
openSUSE / SUSE Linux Enterprise (zypper)
- Install with:
sudo zypper install -y java-11-openjdk-devel - Set JAVA_HOME in system profile or user shell configuration as needed.
Arch Linux (pacman)
- Install JDK and JRE:
sudo pacman -S jdk-openjdk jre-openjdk - Enable and update alternatives automatically via pacman-managed symlinks under
/usr/lib/jvm.
Manual Install from Oracle / Tarball (Generic Linux)
Use this when you need a specific vendor build or version not in the package manager.
- Download the tar.gz from vendor (e.g., Oracle, Eclipse Temurin). Example path:
/opt/java - Extract:
sudo tar -xzf OpenJDK11U-jdk_x64_linux_hotspot_11.0.XX.tar.gz -C /opt/java - Create symlinks:
sudo ln -s /opt/java/jdk-11.0.xx /usr/lib/jvm/java-11-custom - Register with alternatives:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-11-custom/bin/java 1and same for javac. - Export JAVA_HOME and update PATH in
/etc/profile.d/java.sh.
Managing Multiple Java Versions
Production servers or build systems often require multiple JDKs. Key techniques:
- Use
update-alternatives(Debian/Ubuntu) oralternatives(RHEL/Fedora) to switch system-wide default. - For per-application control, set
JAVA_HOMEin the service unit file (systemd) or application startup script to point to the specific JDK. - Tooling such as
sdkmanis helpful for developer workstations to switch JDKs per-project, but avoid sdkman on production servers unless carefully managed.
Security Updates and Maintenance
Important operational recommendations:
- Prefer vendor JDKs packaged for your distribution so you receive security patches through the system package manager.
- Subscribe to vendor security announcements for EOL dates—Java versions reach end-of-life and should be upgraded.
- Use automation (Ansible, Puppet, Chef) to ensure consistent Java versions across fleet and to apply updates during maintenance windows.
Application Scenarios and Best Practices
Which Java edition and install method suits different scenarios?
- Web application servers (Tomcat, WildFly, Jetty) — Use a distro-packaged OpenJDK or a vendor LTS build (e.g., Temurin/Corretto) and pin the version used by your service unit.
- CI/CD and build servers — If multiple Java versions are needed, consider a combination of package manager installs and sdkman for ephemeral build agents to avoid system-wide conflicts.
- Containers and microservices — Use minimal JRE-based images or JLINK to create lean runtimes. For container images, adopt distroless or slim base images with a well-defined JRE to reduce attack surface.
- Development environments — Developer machines can use sdkman to switch versions per project, while keeping the server stack standardized.
Advantages Comparison: OpenJDK vs Oracle JDK vs Vendor Builds
Key tradeoffs to consider:
- OpenJDK — Free, upstream implementation, default in most Linux repos, integrates with system updates. Best for general server use.
- Oracle JDK — Historically had some proprietary components and different licensing; suitable where specific Oracle-only features or compliance are required. Check license terms.
- Vendor builds (Eclipse Temurin, Amazon Corretto, Azul Zing, BellSoft Liberica) — Offer timely security patches, long-term support options, and optimizations. Choose based on support SLA, performance characteristics and available update cadence.
Purchase and Deployment Recommendations
When selecting a hosting or VPS environment for Java workloads, consider:
- CPU and memory sizing—JVMs benefit from predictable vCPU performance and sufficient RAM for heap allocation.
- Disk I/O and storage type—for heavy logging, choose SSD-backed storage with throughput guarantees.
- Backup and snapshot capabilities—for stateful applications, ensure consistent backups and the ability to clone images with preinstalled JDKs.
- Managed vs unmanaged—if you want a fully managed stack, choose providers offering OS patching and security lifecycle management; otherwise ensure you have automation for updates.
For those evaluating a reliable low-latency VPS provider in the United States, consider a provider that offers flexible plans and immediate provisioning—for example, check out a reputable option like USA VPS at VPS.DO to pair your Java applications with consistent infrastructure.
Practical Example: Installing OpenJDK 11 on Ubuntu 22.04
Concise commands to copy-paste for a fast setup:
sudo apt updatesudo apt install -y openjdk-11-jdkjava -version(should report OpenJDK 11)- Create
/etc/profile.d/java.shwith:export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64andexport PATH=$JAVA_HOME/bin:$PATH
Summary
Installing Java on Linux is straightforward if you follow distribution-specific package-manager methods for ease of updates or use vendor tarballs when you need precise control. For production environments, prefer package-managed JDKs or vendor-supported builds to keep up with security patches. Manage multiple JDKs with the alternatives system, set JAVA_HOME for applications that require it, and automate deployments and updates. When choosing infrastructure for Java workloads, prioritize predictable CPU performance, sufficient RAM and SSD-backed storage—learn more about suitable hosting options like a USA VPS at VPS.DO to ensure your Java applications run reliably and scale as needed.