9

Install Java 17 (OpenJDK 17) on Fedora 35/34/33/32

 2 years ago
source link: https://computingforgeeks.com/install-oracle-java-openjdk-fedora-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Install Java 17 (OpenJDK 17) on Fedora 35/34/33/32
Search

In our today’s guide, we’ll talk about how to install Java 17 (OpenJDK 17) on Fedora 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 35/34/33/32 by following the steps below.

For Ubuntu / Debian, use: Install Oracle Java 17 (OpenJDK 17) on Debian

Option 1: Install OpenJDK 17 on Fedora 35/34/33/32

Visit JDK 17 releases page to download the latest archive.

sudo dnf -y install curl wget
wget https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz

Extract the downloaded OpenJDK 17 archive file using tar command.

tar xvf openjdk-17_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/jdk.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/jdk.sh

Confirm Java version.

$ echo $JAVA_HOME
/opt/jdk-17

$ java -version
openjdk 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 Fedora35/34/33/32

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
java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-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 Fedora35/34/33/32

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: 

Video Courses to Learn Java Programming Language:

Recommended books:

Enjoy your Java Development on a Linux machine and check other related guides in our blog.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK