Java is a popular, general-purpose programming language designed to be platform-independent. It is widely used to develop enterprise-level, mobile, and web applications. One of the main benefits of using Java is its ability to run on different operating systems and devices, making it a versatile choice for development projects. Additionally, Java offers several features that make it an ideal choice for many applications. These features include:
- Object-oriented programming: Java is based on object-oriented programming, allowing developers to create modular and reusable code.
- Platform independence: Java code can be run on multiple platforms, including Windows, Mac, and Linux, without needing modification.
- Automatic memory management: Java uses Garbage Collection to manage memory automatically, reducing the risk of memory leaks and other issues.
- Extensive library of reusable code: Java has a library of pre-written code called the Java Standard Library, which developers can use to perform common tasks.
- Strong security features: Java includes features such as sandboxing and code signing, which can help to protect applications from malicious attacks.
- Multi-threading: Java allows for creating multiple threads within a single program, making it well-suited for concurrent and parallel processing.
These features make Java an excellent choice for many applications, from small projects to large enterprise systems. This guide will show you how to install the three Long-Term Support (LTS) versions of Java, namely Java 17, Java 11, and Java 8, on your Fedora Linux system using the DNF package manager.
Table of Contents
Step 1: Update Fedora
Before proceeding with the installation, updating your system to the latest version is recommended to minimize conflicts that may arise during the process. This can be done by running an update command on your system.
sudo dnf upgrade --refresh
Step 2: Install Java
First, you should list the versions of Java available on your system using the following command.
dnf search openjdk
If you’re looking for a specific version, you can use the grep command to filter the results. For instance, if you want to find the Java 17 LTS version, you would use the following command.
dnf search openjdk | grep java-17
Next, you have various options to install Java on your system. Below will focus on the main versions.
Install Java 17 LTS
Java 17, the latest Long-Term Support (LTS) version of the Java programming language, was released in September 2021. It includes new features such as Sealed Classes and Interfaces, which enable developers to create stricter class hierarchies and enhance code readability and maintainability. Additionally, it also provides performance and security enhancements.
Install Java 17 standard packages.
sudo dnf install java-17-openjdk
Install Java 17 for headless environment packages.
sudo dnf install java-17-openjdk-headless
Install Java 17 development packages.
sudo dnf install java-17-openjdk-devel
Install Java 11 LTS
Java 11 is a Long-Term Support (LTS) release of the Java programming language, first released on September 25, 2018. It introduced several new features, such as the Local-Variable Syntax for Lambda Parameters, which allows developers to use the var keyword for lambda expressions. It also includes new standard libraries, such as the HTTP Client API, which allows developers to send HTTP requests and receive responses more naturally. Java 11 also removed some features that were deprecated in previous versions, such as removing the Java EE and CORBA modules. Java 11 is also the reference implementation for Java SE 11 and is considered a significant release for Java. The end-of-life date for active support of Java 11 is September 2026, and the end-of-life date for security support is September 2031, which means it will no longer receive any updates or security patches after that date.
Install Java 11 standard packages.
sudo dnf install java-11-openjdk
Install Java 11 for headless environment packages.
sudo dnf install java-11-openjdk-headless
Install Java 11 development packages.
sudo dnf install java-11-openjdk-devel
Install Java 8 LTS
Java 8 is a Long-Term Support (LTS) release of the Java programming language, first released on March 18, 2014. It introduced several new features, such as Lambda expressions, a new date, and time API, and the stream API, allowing developers to perform functional-style operations on stream elements. Another significant change in Java 8 is the introduction of default and static methods in interfaces, which allows adding new functionality to existing classes without breaking existing code. Java 8 was considered a significant release and greatly impacted the Java ecosystem. The end-of-life date for active support of Java 8 is December 31, 2020, and the end-of-life date for security support is December 31, 2023, which means it will no longer receive any updates or security patches after that date.
Install Java 8 standard packages.
sudo dnf install java-1.8.0-openjdk
Install Java 8 for headless environment packages.
sudo dnf install java-1.8.0-openjdk-headless
Install Java 8 development packages.
sudo dnf install java-1.8.0-openjdk-devel
Additional Commands & Tips
Switching Java Versions
As a developer, it is common to have multiple versions of JDK or OpenJDK installed on a system. Depending on the task or project, you may need to switch between different versions or set one as the default. This can be easily accomplished through the use of a command.
sudo update-alternatives --config java
The command will display the default and all other versions in a numbered list on the terminal. It will prompt you to select which version you want to set as the default by entering the corresponding number. For example, if you change the default version from Java 17 LTS to Java 11 LTS, you will enter the number 2 and press the Enter key.
To verify the change, you can run the version command on your system.
In conclusion, installing a Long-Term Support (LTS) version of Java, such as Java 17, Java 11, or Java 8, on Fedora Linux is a straightforward process. Once installed, you can use the command line to set the default version of Java and verify the installation. It’s important to note that LTS versions of Java are intended for use in production environments and are supported longer than standard releases, making them an excellent choice for long-term projects. Additionally, keeping track of the end-of-life date for the version of Java you’re using is essential to plan your migration to a newer version promptly.