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.

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:
# 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 -versionFor 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 Distribution | Package Manager | Installation Command | Configuration Command |
|---|---|---|---|
| Ubuntu / Debian | APT | sudo apt install openjdk-17-jdk -y | sudo update-alternatives --config java |
| Fedora / RHEL 8+ | DNF | sudo dnf install java-17-openjdk-devel -y | sudo alternatives --config java |
| CentOS 7 | RPM / Oracle | sudo rpm -Uvh jdk-17_linux-x64_bin.rpm | sudo update-alternatives --config java |
| Arch Linux | Pacman | sudo pacman -S jdk17-openjdk | sudo archlinux-java set java-17-openjdk |
| Manual (Tarball) | Generic Linux | Extract .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 javaThis will list the installed Java versions as shown in the screenshot below.

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
yumrepositories only provide OpenJDK up to version 11. Runningyum install java-17-openjdk-develwill output aNo package availableerror. 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
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 javatype the number in front of the Java 17 entry and hit enter, in my case, it's 3 so I'll enter 3.

- Verify the Installation:
Lastly, check the Java version by running the following command
java -version
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 -versionManual 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/setupswith your actual JDK installation path
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 -versionConclusion
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'.


