How to Install Java 17 LTS on Fedora 36 Linux

Java is a general-purpose, class-based, object-oriented multipurpose programming language that is popular due to the design of having lesser implementation dependencies, meaning that the compiled Java code can be run on all platforms that support Java without the need for recompilation. Java is also fast, secure, and reliable, therefore. It is widely used for developing Java applications in laptops, data centers, game consoles, scientific supercomputers, cell phones, etc.

JDK 17 (JDK 17) has brought forward new language enhancements, updates to the libraries, support for new Apple computers, removals and deprecations of legacy features, and work to ensure Java code written today will continue working without change in future JDK versions.

In the following tutorial, you will learn how to install the latest Java 17 (JDK 17) on Fedora 36 Workstation or Server using two methods, by installing the RPM or installing the archive format; both methods involve downloading Java directly from Oracle as only OpenJDK is supported on Fedora natively.

Update Fedora

First, update your system to ensure all existing packages are up to date. This will ensure no conflicts arise as best as possible during the installation.

sudo dnf upgrade --refresh -y

Install Java 17 LTS (JDK 17) – Oracle RPM

The first method is to download the RPM to install JDK 17. This method is quick and straightforward. However, this method does not leave any room for customization for the installation, which developers often prefer.

First, visit the downloads page and download the latest RPM.

Arm 64 RPM Package:

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

x64 RPM Package (Most Users):

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

Next, once the RPM has finished downloading, execute the following command to install JDK 17.

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

Confirm the installation by checking the version and build number to verify the installation.

java --version

Example output:

How to Install Java 17 LTS on Fedora 36 Linux

Install Java 17 LTS (JDK 17) – Manual Method

The second option is to install Java JDK 17 manual method that benefits users more freedom and power on what they want and where installed on their system, when to update, and if need be, install multiple versions more efficiently.

Download Latest Java 17 Build

Visit the downloads page to get the latest build version link, then use the following curl command.

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

Once the download is complete, you need to extract the archive.

tar -xvf jdk-17_linux-x64_bin.tar.gz

Configure and Install JDK 17

Next, move the extracted archive directory into the /opt/ location. You can also rename the folder if you like. The tutorial will use jdk-17, but if you prefer to keep the versions separate for future use, use /opt/ without jdk-17 at the end of the following command.

sudo mv jdk-17.* /opt/jdk-17

Now you need to set the environment variables as below.

export JAVA_HOME=/opt/jdk-17
export PATH=$PATH:$JAVA_HOME/bin

Java 17 is now installed. To confirm, use the following commands.

java --version
echo $JAVA_HOME

Example output:

How to Install Java 17 LTS on Fedora 36 Linux

Test Java 17 LTS – Create Hello World Application

To finish off, it is always handy to test installations of these kinds to confirm everything is working correctly after being installed. The easy way is to create a small program script to try using the famous Hello World example.

First, create the Java program file as follows

sudo nano hello.java

Next, add the following Java code into the file:

public class hello {
  public static void main(String[] args) {
    System.out.println("G'day from LinuxCapable!");
  }
}

Save the file (CTRL+O), then exit (CTRL+X).

Next, compile the code with the javac command as follows.

javac hello.java

Finally, run the Java code with the following command.

java hello

Example output:

How to Install Java 17 LTS on Fedora 36 Linux

Congratulations, everything is working correctly.

Switching Default Versions of JDK

Typically, most systems will start to have multiple installations and versions of JDK or OpenJDK, especially as a developer. Sometimes, you may want one set as default but sometimes need to switch them around. This can be easily achieved using the following command.

sudo update-alternatives --config java

Example output:

How to Install Java 17 LTS on Fedora 36 Linux

The above command will print a list of the default version and all other versions in a numbered list.

In the terminal, you will see the message to choose which number to set as default, enter the number, and press the ENTER KEY, and that’s it you’ve swapped default versions.

Comments and Conclusion

In the tutorial, you have learned how to download and install the latest version of Java 17 (JDK 17).

In conclusion, upgrading Java can be a daunting task. However, it is worth the effort in the long term as Java 17 will become an LTS support version with improvements for some time to come.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!