In our today’s guide, we’ll talk about how to install Java 17 (OpenJDK 17) on Fedora 38/37/36/35/34/33/32. 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
Option 1: Install OpenJDK 17 on Fedora 38/37/36/35/34/33
Visit JDK 17 releases page to download the latest archive.
sudo dnf -y install curl wget
wget https://download.java.net/openjdk/jdk17/ri/openjdk-17+35_linux-x64_bin.tar.gz
Extract the downloaded OpenJDK 17 archive file using tar command.
tar xvf openjdk-17+35_linux-x64_bin.tar.gz
Move the resulting folder to /opt directory.
sudo mv jdk-17 /opt/
Configure Java environment:
sudo tee /etc/profile.d/jdk17.sh <<EOF
export JAVA_HOME=/opt/jdk-17
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 version "17" 2021-09-14
OpenJDK Runtime Environment (build 17+35-2724)
OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)
Option 2: Install Java SE Development Kit 17 on Fedora
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
warning: jdk-17_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:jdk-17-2000:17-ga ################################# [100%]
Confirm Java version installed
$ java -version
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment (build 17+35-2724)
OpenJDK 64-Bit Server VM (build 17+35-2724, 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
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
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.