In our today’s guide, we’ll talk about how to install Java 17 (OpenJDK 17) on Fedora. Java 17 is now available for general usage – Check out General Availability release notes for new features. Production-ready binaries are also available from Oracle for Java SE Development Kit 17.
JDK 17 is the open-source reference implementation of version 17 of the Java SE Platform as specified by by JSR 388 in the Java Community Process. Install JDK | OpenJDK 17 on your Fedora by following the steps below.
For Ubuntu / Debian, use: Install Oracle Java 17 (OpenJDK 17) on Debian
1) Installing OpenJDK 17 on Fedora
The easiest is installation from OS repositories.
sudo dnf install java-17-openjdk java-17-openjdk-devel
Accept installation prompting
Transaction Summary
======================================================================================================================================================================================================
Install 3 Packages
Total download size: 50 M
Installed size: 196 M
Is this ok [y/N]: y
Running these commands will output the default version of Java in the system.
$ java -version
openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment (Red_Hat-17.0.10.0.7-3) (build 17.0.10+7)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.10.0.7-3) (build 17.0.10+7, mixed mode, sharing)
Manual installation method
You can also visit JDK 17 releases page to download the latest archive if you don’t prefer system packages.
sudo dnf -y install curl wget
wget https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz
Extract the downloaded OpenJDK 17 archive file using tar command.
tar xvf openjdk-17.0.2_linux-x64_bin.tar.gz
Move the resulting folder to /opt directory.
sudo mv jdk-17.0.2 /opt/
Configure Java environment:
sudo tee /etc/profile.d/jdk17.sh <<EOF
export JAVA_HOME=/opt/jdk-17.0.2
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
Source your profile file and check java
command
source /etc/profile.d/jdk17.sh
Confirm Java version.
$ echo $JAVA_HOME
/opt/jdk-17
$ java -version
openjdk 17.0.10 2024-01-16
OpenJDK Runtime Environment Temurin-17.0.10+7 (build 17.0.10+7)
OpenJDK 64-Bit Server VM Temurin-17.0.10+7 (build 17.0.10+7, mixed mode, sharing)
2) Installing Java SE Development Kit 17
If you choose to go with Java SE Development Kit 17, download RPM package for CentOS / RHEL / Fedora system using the command below.
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
Then install the RPM package using the yum or rpm command.
$ sudo rpm -Uvh jdk-17_linux-x64_bin.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:jdk-17-2000:17.0.9-11 ################################# [100%]
Confirm Java version installed
$ java -version
java version "17.0.9" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)
Configure Java environment.
cat <<EOF | sudo tee /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/java/default
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
To use Java Home, source the file.
source /etc/profile.d/jdk.sh
3) Test Java 17 Installation on Fedora
Create a HelloWorld Java program.
$ vi HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}
}
Compile Java code.
java HelloWorld.java
Run your Java program.
$ java HelloWorld
Hello, World
4) Choosing Default Version of Java
If you have more than one version of Java installed, you can set default one using alternatives command.
sudo alternatives --config java
Select Java to set as default.
$ sudo alternatives --config java
There is 1 program that provides 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/java/jdk-17/bin/java
Enter to keep the current selection[+], or type selection number:
Recommended books;
Enjoy your Java Development on a Linux machine and check other related guides in our blog.