How to Install Java 17 on Linux: Ubuntu, Debian, CentOS 7 & Fedora

Step-by-step guide to install Java 17 on Linux: Ubuntu 24.04/22.04, CentOS 7, RHEL, AlmaLinux, Arch, and Fedora. Configure JAVA_HOME and alternatives easily.

Banner showing Java logo and step-by-step install commands for Java 17 on Linux

Hello guys, today in this tutorial, we will cover how to install Java 17 JDK on your machine in two different ways. This installation guide covers the steps for all major Linux distros: Ubuntu, Debian, Fedora, CentOS 7, RHEL, AlmaLinux, and Arch Linux.

Java is a popular programming language and Java 17 is a primary Long Term Support (LTS) release of the Java platform. Installing Java 17 JDK allows you to use sealed classes, pattern matching, records, and enhanced garbage collection in production.

Quick One-Liner Install Commands

If you just need the copy-paste command for your distro, here they are:

bash
# Ubuntu / Debian / Linux Mint (APT)
sudo apt update && sudo apt install openjdk-17-jdk -y

# Fedora / RHEL 8+ / AlmaLinux 8+ / Rocky Linux (DNF)
sudo dnf install java-17-openjdk-devel -y

# CentOS 7 / RHEL 7 (Oracle RPM - CentOS 7 repos do not have OpenJDK 17)
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm && sudo rpm -Uvh jdk-17_linux-x64_bin.rpm

# Arch Linux / Manjaro (Pacman)
sudo pacman -S jdk17-openjdk

# Verify installation
java -version

For the detailed step-by-step walkthrough with screenshots, environment variable setup, and the manual non-root tarball method, continue reading below.

Attention! Some commands on this website require superuser access and could potentially cause system issues if not executed properly. You're in charge of any consequences, and I'm not responsible. Happy coding!

How to install Java 17?

Linux Package Manager Installation Matrix

Linux DistributionPackage ManagerInstallation CommandConfiguration Command
Ubuntu / DebianAPTsudo apt install openjdk-17-jdk -ysudo update-alternatives --config java
Fedora / RHEL 8+DNFsudo dnf install java-17-openjdk-devel -ysudo alternatives --config java
CentOS 7RPM / Oraclesudo rpm -Uvh jdk-17_linux-x64_bin.rpmsudo update-alternatives --config java
Arch LinuxPacmansudo pacman -S jdk17-openjdksudo archlinux-java set java-17-openjdk
Manual (Tarball)Generic LinuxExtract .tar.gz to /opt/java/Export JAVA_HOME in ~/.bashrc

let's start by checking if Java is installed already, as there might be multiple versions of Java but the default is set to some other version, so we will check what versions of Java are installed in the system already.

open the terminal and run the following command to list the installed Java versions

update-alternatives --config java

This will list the installed Java versions as shown in the screenshot below.

Screenshot of update-alternatives command showing java versions
Screenshot of update-alternatives command showing java versions

The 3rd entry in this screenshot is java 17 (*+ 3 /usr/lib/jvm/jdk-17-oracle-x64/bin/java), if this is the case for you, then java 17 is already installed on your machine, but not set as default, to make it default, just enter the number in front of the java 17 entry and its done, but if you don't find any such entries, then follow this guide.

For Fedora, RHEL, CentOS & AlmaLinux

⚠️ Important Note for CentOS 7 Users: The default CentOS 7 yum repositories only provide OpenJDK up to version 11. Running yum install java-17-openjdk-devel will output a No package available error. On CentOS 7, use the official Oracle RPM installation steps shown below.

  • Download the JDK:
    run the following command in the terminal to download the latest Java 17 JDK
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
  • Install the downloaded RPM binary:
    You might need the superuser rights to execute the following command
sudo rpm -Uvh jdk-17_linux-x64_bin.rpm
  • Add/update the JAVA_HOME and PATH environment variables:
    The following command also needs superuser privileges, this command sets the JAVA_HOME variable and updates the PATH environment variable
bash
cat <<EOF | sudo tee /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
EOF
  • Source the newly created jdk.sh:
    to ensure the environment variables are set properly
source /etc/profile.d/jdk.sh
  • Update the default java executable:
    now run the following command again to verify the installation
sudo update-alternatives --config java

type the number in front of the Java 17 entry and hit enter, in my case, it's 3 so I'll enter 3.

Screenshot of update-alternatives command showing java versions
Screenshot of update-alternatives command showing java versions
  • Verify the Installation:
    Lastly, check the Java version by running the following command
java -version
Screenshot: java -version command output showing java 17 installed
Screenshot: java -version command output showing java 17 installed

Congratulations, you've installed Java 17 on your system.

For Ubuntu-based OS

  • Update the packages repository:
    execute the following command to update the list of packages
sudo apt update
  • Install Java 17 by OpenJDK you need superuser access to run the following command
sudo apt install openjdk-17-jdk
  • Verify the Installation:
    Lastly, check the Java version by running the following command
java -version

Manual method - Non root

You can install Java 17 on your system, even without the root access, follow these steps to set up the Java 17 without superuser access in manual mode, in this approach we will download the tarball (.tar.gz, .tar) and set the environment variables to match our extracted tarball location, this method works for any directory with write access.

  • Navigate to a directory with write access:
    switch to a path where you would like to have your Java 17 installed, e.g.
cd ~/Desktop/setups
  • Download the Java 17 tarball
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
  • Extract the tarball
tar -xvzf jdk-17_linux-x64_bin.tar.gz
  • Set the environment variables:
    make sure to replace the ~/Desktop/setups with your actual JDK installation path
bash
export JAVA_HOME=~/Desktop/setups/jdk-17_linux-x64_bin
export PATH=$PATH:$JAVA_HOME/bin
  • Verify the Installation:
    At last, verify the Java version by running the following command
java -version

Conclusion

Java 17 can be installed easily with or without superuser access by following this step-by-step guide on Ubuntu, Debian, CentOS 7, RHEL, AlmaLinux, and Fedora Linux machines. The default versions can be managed by using the update-alternatives command to easily switch between different java versions.

Frequently Asked Questions:

  • How to install Java 17 on Linux?

    On Ubuntu or Debian, run 'sudo apt install openjdk-17-jdk -y'. On Fedora or RHEL, run 'sudo dnf install java-17-openjdk-devel -y'. On CentOS 7, install the Oracle RPM using 'sudo rpm -Uvh jdk-17_linux-x64_bin.rpm'. On Arch Linux, run 'sudo pacman -S jdk17-openjdk'.

  • Why does 'yum install java-17-openjdk-devel' fail on CentOS 7?

    CentOS 7 base repositories do not provide OpenJDK 17 packages. To install Java 17 on CentOS 7, download and install the official RPM binary from Oracle using 'wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm && sudo rpm -Uvh jdk-17_linux-x64_bin.rpm', or install Eclipse Temurin via the Adoptium repository.

  • How do I install Java 17 on Ubuntu 22.04 or 24.04 LTS?

    On Ubuntu 22.04 LTS, 24.04 LTS, and newer versions, OpenJDK 17 is available in the main distribution repositories. Run 'sudo apt update && sudo apt install openjdk-17-jdk -y' to install the complete JDK and development tools.

  • How do I install Java 17 on Arch Linux?

    On Arch Linux, install OpenJDK 17 by running 'sudo pacman -S jdk17-openjdk'. To set it as your active system Java environment, execute 'sudo archlinux-java set java-17-openjdk'.

  • How do I set JAVA_HOME in Linux?

    Open your shell profile (~/.bashrc or ~/.zshrc) and add: export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 followed by export PATH=$JAVA_HOME/bin:$PATH. Then run 'source ~/.bashrc' to apply the changes.

  • How do I check which Java version is active?

    Run 'java -version' in your terminal. To switch between multiple installed Java versions, use 'sudo update-alternatives --config java'.

PrevWhat is Computer Programming? Basics for Beginners (With Chart)NextFix ESP32: Failed to Connect: Timed Out Waiting for Packet Header

Related Guides & Deep Dives

#cybersecurity

Ethical Hacking for Absolute Beginners: Full Guide

Learn Ethical Hacking for absolute beginners. Explore the fields in ethical hacking, skills required and tools, resources for practice.

Read Article
#electronics

Basic Electronic Components: Types, Functions & Guide (PDF)

Guide to basic electronic components and functions: resistors, capacitors, diodes, transistors, and ICs with circuit diagrams and free PDF download.

Read Article
#edi

EDI for Beginners: Electronic Data Interchange Guide & PDF

EDI for beginners: Learn Electronic Data Interchange basics with real-world examples, EDI 850/810 transaction sets, process flow diagrams, and free PDF.

Read Article

photo of Madhusudan Babar