In today’s guide, we are going to learn how we can install Java SE 17 on Fedora 35. Java is widely used in programs like Cassandra, Graylog, Wine, etc.
Java delivers thousands of performance, stability, and security updates that is the reason why java is widely used and has a larger community base worldwide.
Java 17 new features
Java 17 includes new language enhancement, updates to the libraries, updates to the new Apple computers, removals, and deprecations of legacy features. Updates include the following:
- Introduction of sealed classes. That is, it restrict which other classes or interfaces may extend or implement them.
- It introduces restore always-strict floating-point semantics
- Introduction of enhanced pseudo random number generator
- Introduction of new MacOS rendering pipeline using the Apple metal API
It also deprecated some old features such as:
- Deprecated the java Applet API
- It removed Remote Method Invocation activation
- Removes the experimental Ahead Of Time and Just In Time compiler
- Deprecated the Security Manager which has been the conerstone of securing client side java code.
Prerequisites
- Have a root user account while running the installation
- Have Fedora 35
Related Articles
Installation Java SE 17 on Fedora 35
1. Run sytem updates
Before you begin any install make sure you run system updates to make your repositories up to date.
$ sudo dnf update -y
2. Installing java 17
Installing java 17 we need to get the installation package from the Oracle download pages. Use the following link to make the download easier and to get the latest version.
$ wget https://download.java.net/java/GA/jdk17.0.1/2a2082e5a09d4267845be086888add4f/12/GPL/openjdk-17.0.1_linux-x64_bin.tar.gz
If you get an error that wget is not installed, you can run the installation with the following command
$ sudo dnf install wget -y
Run the installer again this time it will go through successfully.
Check the downloaded file before extracting it
$ ls
openjdk-17.0.1_linux-x64_bin.tar.gz
Move ahead and extract the contents into your home directory.
$ tar -xzf openjdk-17.0.1_linux-x64_bin.tar.gz
We need to move the contents to the /opt directory
$ sudo mv jdk-17.0.1/ /opt
You can do an ls again to verify that indeed you have moved jdk17 to the opt directory.
Let’s now set our java home directory so that every time you run java application, it knows where to run from. To do that we can do the following;
Open the ~/.bashrc file and add the following
$ sudo nano ~/.bashrc
Add the following contents to the bashrc file
export JAVA_HOME=/opt/jdk-17.0.1
export PATH=$PATH:$JAVA_HOME/bin
Save and exit the nano.
Run source ~/.bashrc so that changes to bashrc file can take effect.
$ source ~/.bashrc
Now we can check the version of the installed java with the following command;
$ java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39)
OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)
Test java 17 program
Let’s test if Java is working correctly. To do that we are going to run our first hello world program
$ sudo nano hello.java
Add the following to your hello.java
public class hello {
public static void main(String[] args) {
System.out.println("Hello, World! from Nextgentips");
}
}
You need to compile the java programs in order to show the output. To run the compilation run the following code
$ javac hello.java
If you don’t run into any errors then it’s time to run your first java program.
$ java hello
Hello, World! from Nextgentips
Setting Java 17 environment
To ensure that you cant run into problems while running java programs, we need to set JAVA_HOME environment where java will be executed. If you don’t set this environment you will encounter errors in the future. To avoid that let’s set the environment.
Let’s check where we have our java 17 with the following command.
$ which java
/opt/jdk-17.0.1/bin/java
You will get the path like this
So let’s set this in our /etc/environment
$ sudo nano /etc/environment
Add the following
export JAVA_HOME=/opt/jdk-17.0.1/bin/java
Save and exit
To apply the changes using the following command
$ source /etc/environment
To check if the environment path is correct use the following command
$ echo $JAVA_HOME
/opt/jdk-17.0.1/bin/java
If you are getting empty results know that you have not applied the changes as required, go back and do source /etc/environment
From here now you will not be required to set the environment every time you install another java version.
Conclusion
You have successfully installed Java 17 on Fedora 35. In case of difficulty consult the documentation