Java Install on Linux: A Step-by-Step Guide

Learn how to install Java on Linux, compare OpenJDK and Oracle JDK, and verify your setup across Debian/Ubuntu, Fedora/RHEL, and Arch. This guide from Install Manual covers methods, troubleshooting, and best practices for developers and admins.

Install Manual
Install Manual Team
·5 min read
Java on Linux - Install Manual
Photo by ignartonosbgvia Pixabay
Quick AnswerSteps

By the end of this guide, you will successfully install Java on Linux across common distributions (Debian/Ubuntu, Fedora/RHEL, Arch). The process covers OpenJDK vs Oracle JDK choices, repository methods, and verifying the installation. You’ll need internet access, a user with sudo privileges, and a terminal. Start by choosing your JDK flavor and method.

Why Java on Linux: Reasons to Install and What You Gain

Java remains one of the most widely used programming languages for server-side applications, desktop apps, and cross-platform tooling. Linux is a natural home for Java deployments, especially on servers, development workstations, and virtualization environments. According to Install Manual, a Linux-based setup often yields smoother automation, easier package management, and long-term security updates for Java runtimes. In this section, you’ll learn why installing Java on Linux is a practical choice for developers, sysadmins, and DIY enthusiasts working on home labs. We’ll cover the major benefits, common use cases, and how selecting the right JDK flavor can affect licensing, updates, and compatibility across distributions.

Choosing the Right JDK: OpenJDK vs Oracle JDK

OpenJDK is the open source implementation of the Java Platform, Standard Edition, and is the default in most Linux distributions. Oracle JDK historically offered commercial features and support options, but licensing terms have evolved; many organizations now rely on OpenJDK for day to day deployments. Install Manual highlights that for most development and production tasks, OpenJDK provides a stable, well-supported path with simple updates. If you have strict licensing needs or require enterprise support, evaluate Oracle JDK or other commercial builds and weigh licensing implications before installation. Both flavors aim to provide compatible runtimes, but your choice can affect update cadence and legal terms.

Download Methods: Package Managers, Tarballs, and PPAs

The simplest way to install Java on Linux is through your distribution's package manager. Debian-based systems use apt, Red Hat-based systems use dnf, and Arch uses pacman. Package managers ensure you receive updates along with the rest of your system. If you need a specific Java version not available in your repo, you can opt for a tarball installation from Oracle or other vendors, or use a Personal Package Archive (PPA) on Debian/Ubuntu. Tarballs give you full control over the installation directory, but you will manage updates manually. PPAs can provide newer builds but require careful maintenance to avoid conflicts.

Debian/Ubuntu: Install OpenJDK via APT

Debian and Ubuntu communities typically package OpenJDK in their official repositories. Installing OpenJDK via apt is fast, safe, and integrates with your system. Start by updating the package index, then install the default JDK package, which points to a current OpenJDK release. After installation, verify the runtime and compiler versions to confirm a successful setup. If you need a specific Java version, you can install a version-specific package like java-17-openjdk or openjdk-11-jdk depending on your distribution version. Always confirm with a quick java -version check to validate the environment.

Debian/Ubuntu: Install Oracle JDK via Tarball

If you require Oracle JDK or a vendor tarball for licensing reasons, you can install Java by downloading the tarball, extracting it to a system directory, and updating environment variables. This method gives you full control over the Java installation path. Typical steps include downloading the tarball to a secure location, extracting it to a directory such as /usr/local, creating a symlink for easy future upgrades, and configuring JAVA_HOME and PATH in your shell profile. After setup, run java -version to verify the installation and ensure the system uses the intended JDK.

Fedora/RHEL: Install OpenJDK with DNF

Fedora and RHEL-based systems commonly provide OpenJDK via the DNF package manager. Installing the devel package is useful for development tasks that require javac and other tools. Use a version-appropriate package such as java-17-openjdk-devel or java-11-openjdk-devel. After installation, verify the toolchain with java -version and javac -version. If you manage multiple JDKs, you can switch defaults with the system's alternatives mechanism to ensure consistency across build tools and scripts.

Arch Linux: Install OpenJDK with Pacman

Arch users typically install OpenJDK from the official repositories using pacman. A minimal JDK installation can be completed with a single command, and Arch provides a helper utility to switch between installed Java versions. After installation, confirm the runtime with java -version and check the active Java environment with archlinux-java status. Setting a default JDK with archlinux-java set integrates with your shell and build tools just like on other distributions.

Verifying installation and Setting JAVA_HOME

Verification starts with checking the runtime and compiler versions. Run java -version and javac -version to confirm both runtime and tool availability. Next, locate the Java home path by resolving the java binary location, then export JAVA_HOME to that path and add the bin directory to PATH. Recommended practice is to place this configuration in a file loaded by your shell at login, such as a profile script in /etc/profile.d or your user home directory. This ensures tools like Maven, Gradle, and IDEs can reliably locate Java.

Managing Multiple Java Versions and PATH Updates

If you maintain multiple JDKs, you’ll want a predictable method to switch between them. On Debian-based systems, update-alternatives lets you configure the default java and javac. On Red Hat-based systems, use alternatives config. Arch users switch with archlinux-java. After selecting a default, re-check java -version to verify the active runtime. This approach avoids breaking existing scripts and build environments when you upgrade or test new JDKs.

Troubleshooting Common Issues

If java is not found, recheck PATH and JAVA_HOME, and confirm that your shell profile is loaded. Conflicts often occur when an older JDK remains in the PATH; removing or relocating old installations can resolve this. If a version mismatch appears in a build tool, ensure the tool points to the correct java and javac binaries. Permissions can also block access to the JDK directory; verify that you have read and execute rights on the java binaries. When in doubt, a clean reinstallation using your distro package manager reduces conflicting files and simplifies updates.

Using Java for Development: Build Tools and Project Setups

With Java installed, many developers proceed to set up build tools such as Maven or Gradle. On most Linux distros these tools are available from official repositories. Installing them via the package manager ensures compatibility with the installed JDK. After installation, configure your build tool to locate Java via JAVA_HOME or by using the system Java binaries in PATH. This alignment is essential for consistent builds across CI pipelines and local development environments.

Maintenance, Updates, and Best Practices

Keep Java up to date by applying security and bug fixes from your distro or by manually updating Oracle JDK tarballs when you manage them. Enable automatic security updates where appropriate for critical systems, but carefully test major JDK upgrades in a staging environment before production. Document the chosen JDK flavor and version in your project or system administration notes to avoid drift over time. Regularly review your PATH and JAVA_HOME settings after system changes or user migrations to maintain reliable Java tooling.

Tools & Materials

  • A Linux machine with sudo access(Debian/Ubuntu, Fedora/RHEL, Arch are common targets)
  • Active internet connection(Needed to download JDK packages or tarballs)
  • Terminal or SSH client(For executing commands and scripts)
  • Text editor(Useful for editing profile scripts and environment variables)
  • Optional: build tools(Maven, Gradle, or similar for development work)

Steps

Estimated time: 30-60 minutes

  1. 1

    Choose your JDK flavor

    Decide between OpenJDK for open source simplicity or Oracle JDK for licensing options. This choice affects update cadence and distribution compatibility across your Linux family.

    Tip: If you are new to Java on Linux, start with OpenJDK from your distro repository.
  2. 2

    Update your package index

    Refresh the repository metadata so you install the latest available JDK. The command varies by distro, but involves a system update invocation.

    Tip: Always run with sudo to access system repositories.
  3. 3

    Install OpenJDK via your distro's package manager

    Install the default JDK package or a version-specific JDK package from your distro repo to get a ready-to-use runtime and compiler.

    Tip: Use a version like java-17-openjdk-devel if you need development headers.
  4. 4

    Verify Java installation

    Run java -version and javac -version to confirm the Java runtime and compiler are installed and accessible.

    Tip: Check for 64-bit architecture support if you encounter binary compatibility issues.
  5. 5

    Configure JAVA_HOME and PATH

    Set JAVA_HOME to the JDK installation path and add the bin directory to your PATH so tools can locate Java.

    Tip: Place settings in a profile script loaded at login for consistency across sessions.
  6. 6

    Switch between multiple JDKs if needed

    If you install more than one JDK, use the distro's alternatives system to set the default Java and Javac paths.

    Tip: After changing defaults, re-run java -version to verify the active runtime.
  7. 7

    Install a build tool (optional)

    Install Maven or Gradle if your projects require a build pipeline or dependency management.

    Tip: Ensure the build tool is compatible with your chosen JDK version.
  8. 8

    Test with a simple program

    Create a small HelloWorld.java, compile and run it to confirm a functioning development environment.

    Tip: Keep a copy of the sample file for quick regression tests after upgrades.
Pro Tip: Use default-jdk on Debian-based systems to quickly get a supported OpenJDK runtime.
Pro Tip: Leverage update-alternatives to manage multiple Java versions without breaking scripts.
Warning: Oracle JDK licensing terms may affect production use; prefer OpenJDK where possible.
Note: Document your chosen Java version in project READMEs to reduce drift during upgrades.

Got Questions?

What is the difference between OpenJDK and Oracle JDK?

OpenJDK is the open source reference implementation of the Java Platform. Oracle JDK includes licensing terms that may affect production use; choose based on licensing needs and support requirements.

OpenJDK is open source and widely supported by Linux distros; Oracle JDK has licensing considerations that may matter for production deployments.

Can I install multiple Java versions on Linux?

Yes. You can install several JDKs side by side and switch the default using the system's alternatives mechanism or archived Java setups.

Yes, you can have multiple JDKs and switch which one is used by default.

How do I verify the Java installation?

Run java -version to check the runtime and javac -version for the compiler. Also confirm JAVA_HOME points to the correct JDK path.

Check the runtime with java -version and confirm JAVA_HOME is set correctly.

Why set JAVA_HOME?

Many development tools rely on JAVA_HOME to locate the Java runtime. Setting it ensures consistent behavior across IDEs and build tools.

JAVA_HOME tells tools where Java is installed, ensuring consistency across apps.

What if the distro repository lacks a Java version I need?

Consider installing a tarball from the vendor or enabling a trusted PPA, then configure JAVA_HOME and PATH accordingly.

If the repo lacks the version you need, use a tarball or a trusted PPA and set JAVA_HOME.

Is Java 17 still a good choice for new projects?

Java 17 is an LTS release and widely supported across distros; check your project and toolchain requirements before upgrading.

Java 17 is a long term support release and works well for most projects, but verify compatibility with your tools.

Watch Video

Main Points

  • Decide between OpenJDK and Oracle JDK based on licensing and support
  • Use your distro package manager for easy maintenance
  • Set JAVA_HOME and PATH correctly for tooling compatibility
  • Switch between JDKs with a simple command when needed
  • Verify installation with java -version and a quick test program
Process infographic showing steps to install Java on Linux
A concise visual guide to installing Java on Linux across distributions

Related Articles