How to Install Java 17 on Fedora 35/34 & CentOS/RHEL 8

Channel: Linux
Abstract: use alternatives command command to change default Java version. The alternatives binary is provided by chkconfig package. sudo alternatives --config

Java 17 is the latest long-term support release for the Java SE platform. As this is a LTS version, it will be supported for till September 2024. Java 17 comes with multiple improvements and bug fixes. The workstation users should consider to upgrade to this version. Also production users can consider to upgrade after checking all the application compatibility check.

This tutorial is written for the instructions to install Latest Java version on Fedora, CentOS and Redhat systems. So, follow this article to install Java 17 on your Fedora and CentOS/RHEL systems.

  • You may like: Install Java 11 on CentOS/RHEL & Fedora
  • Step 1 – Download Java 17

    Download the latest Java SE Development Kit 17 non LTS release from its official download page or use following commands to download from command line.

    wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm 
    
    Step 2 – Install Latest Java on Fedora & CentOS

    After downloading the Java package file, use 「rpm」 command to install it on your system. The non-root user must use 「sudo」 run command with special privileges that allows the installation.

    Execute the following command to install Java 17:

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

    Once the installation completed, this version will be the default Java version. But it case the system is still using the older version, use alternatives command command to change default Java version. The alternatives binary is provided by chkconfig package.

    sudo alternatives --config java
    
    Output 
    There are 2 programs which provide 'java'.
    
      Selection    Command
    -----------------------------------------------
     + 1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.14.0.9-2.fc35.x86_64/bin/java)
    *  2           /usr/java/jdk-17.0.2/bin/java
    
    
    Enter to keep the current selection[+], or type selection number: 2 
    

    According to the above screenshot, there are 2 versions installed. Java 17 is listed on number 2, So input numeric 2 and press Enter. This will change the default Java version to 17 on your system.

    Step 3 – Check Default Java Version

    Check the installed Java version on your system using the following command.

    java -version 
    
    Output 
    java version "17.0.2" 2022-01-18 LTS
    Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
    Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
    
    Step 4 – Setup Java Environment Variables

    Most of the Java-based applications uses environment variables to work. Set the Java environment variables using the following commands

    • Setup JAVA_HOME Variable
    export JAVA_HOME=/usr/java/jdk-17.0.2 
    
  • Setup PATH Variable
  • export PATH=$PATH:/usr/java/jdk-17.0.2/bin 
    

    Also put all above environment variables in /etc/environment file for auto loading on system boot.

    Conclusion

    This tutorial helped you to install Java 17 on Fedora 35/34/33 and CentOS/RHEL 8/7 Linux systems.

    Ref From: tecadmin

    Related articles