How to Install Java JDK 17 on Fedora 36 / Fedora 35 / 34

0

The Java JDK (Java Development Kit) is a software development environment used for developing Java Applications. It is a collection of programming tools, notably JRE (Java Runtime Environment), Java (Loader for Java Application), Javac (Compiler), Jar (Archiver), etc.

Java JRE (Java Runtime Environment) contains tools for running Java applications.

OpenJDK is an open-source implementation of the Oracle Java SE platform edition, and there is no technical difference between OpenJDK and Oracle JDK.

Here, we will see how to install Java JDK 17 on Fedora 36 / Fedora 35.

Install Java on Fedora 36

You can install OpenJDK or Oracle Java as per your requirement. Also, you can have multiple versions of Java (OpenJDK and Oracle Java) on your system.

Install OpenJDK

Installing OpenJDK is a pretty straightforward process in Fedora. You can use the dnf command to install OpenJDK from the Fedora repository.

Install OpenJDK JDK

# Java JDK 17

sudo dnf install -y java-17-openjdk-devel

# Java JDK 11

sudo dnf install -y java-11-openjdk-devel

# Java JDK 8

sudo dnf install -y java-1.8.0-openjdk-devel

Install OpenJDK JRE

# Java JRE 17

sudo dnf install -y java-17-openjdk

# Java JRE 11

sudo dnf install -y java-11-openjdk

# Java JRE 8

sudo dnf install -y java-1.8.0-openjdk

Install Oracle Java

There is no separate JRE (Java Runtime Environment) anymore. Instead, Oracle JDK now provides JRE as well.

Download Oracle Java JDK

You can either use the command line or browser to download the JDK.

Go to the Oracle JDK page to download packages using the browser. Then, download the rpm binary package for easy installation.

Oracle Java JDK 17 (LTS):

Download Oracle Java 17 (v17.0.3.1)

Oracle Java JDK 11 (LTS):

Download Oracle Java 11 (v11.0.15.1) (Login Required)

Oracle Java JDK 8:

Download Oracle Java 8 (v8u333) (Login Required)

If you still want to download through the command line, install the wget package.

sudo dnf install -y wget

Then, use the below command to download Oracle Java using the terminal.

# Oracle Java JDK 17

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

# Oracle Java JDK 11

<LOGIN REQUIRED>

# Oracle Java JDK 8

<LOGIN REQUIRED>

Install Oracle Java JDK

After downloading the package, install Oracle Java JDK using the rpm command.

# Oracle Java JDK 17

sudo rpm -ivh jdk-17_linux-x64_bin.rpm

# Oracle Java JDK 11

sudo rpm -ivh jdk-11.0.15.1_linux-x64_bin.rpm

# Oracle Java JDK 8

sudo rpm -ivh jdk-8u333-linux-x64.rpm
By default, Java JDK is installed in /usr/java/ directory. To install Oracle JDK to a custom directory, use the rpm -ivh –prefix=/<path>/ rpmfile command.

Set Default Java Version

Use the alternatives command to set the default java version.

sudo alternatives --config java

Select Java:

If your system has multiple Java versions, the above command will list all Java versions.

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
 + 1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-4.fc35.x86_64/bin/java)
   2           java-latest-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.1.0.12-2.rolling.fc35.x86_64/bin/java)
*  3           /usr/java/jdk-17.0.1/bin/java

Enter to keep the current selection[+], or type selection number: 3

Enter the number below the selection column to set the default Java version.

Here, I chose 3 for Oracle Java 17.

Verify Java Version

Check the java version using the following command.

java -version

Output:

java version "17.0.3.1" 2022-04-22 LTS
Java(TM) SE Runtime Environment (build 17.0.3.1+2-LTS-6)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.3.1+2-LTS-6, mixed mode, sharing)

The output may vary depending upon the package and the version you chose to be the default Java version.

Setup Environmental Variables

Java applications often require JAVA environment variables to be set in the system. To set JAVA variables at the system level, create a file in the /etc/profile.d directory.

sudo vi /etc/profile.d/java.sh

Then, add the required variables.

To set the environment variables for a particular user, place the below variables in the .bash_profile file in the home directory.

export PATH=$PATH:/usr/java/jdk-17.0.1/bin/
export JAVA_HOME=/usr/java/jdk-17.0.1/

Finally, load the environments into the current session.

sudo source /etc/profile.d/java.sh

Conclusion

That’s All. I hope this post helped you install Java JDK 17 on Fedora 35.

You might also like