The Java Development Kit (JDK) is required for compiling and running Java applications. When installing the JDK, you also install the Java Runtime Environment (JRE), which is necessary for executing Java applications. Red Hat, CentOS, and Fedora support various versions of JDK, including OpenJDK, an open-source implementation of the Java Standard Edition (Java SE) platform.
OpenJDK can be installed on Red Hat-based distributions using package managers such as yum or dnf. The available versions of OpenJDK include Java 8, Java 11, and Java 17, depending on your requirements. Red Hat provides pre-built OpenJDK packages, ensuring a stable and secure environment for your Java applications.
Selecting the appropriate version of OpenJDK is crucial. Java 8 is widely used in legacy systems, while Java 11 and Java 17 offer newer features and long-term support. Installation involves a simple command-line process where you can choose the required JDK version for your development environment.
Steps to install OpenJDK on Red Hat, CentOS, and Fedora:
- Open the terminal.
- Search for available OpenJDK versions.
$ dnf search openjdk-devel Last metadata expiration check: 0:00:17 ago on Thu 26 Jan 2023 03:29:49 PM +08. ========================= Name Matched: openjdk-devel ========================== java-1.8.0-openjdk-devel.aarch64 : OpenJDK 8 Development Environment java-11-openjdk-devel.aarch64 : OpenJDK 11 Development Environment java-17-openjdk-devel.aarch64 : OpenJDK 17 Development Environment
- Install the required version of OpenJDK.
$ sudo dnf install --assumeyes java-1.8.0-openjdk-devel [sudo] password for user: CentOS Stream 9 - BaseOS 256 kB/s | 4.7 MB 00:18 CentOS Stream 9 - AppStream 689 kB/s | 13 MB 00:19 CentOS Stream 9 - Extras packages 644 B/s | 10 kB 00:15 Dependencies resolved. ================================================================================ Package Arch Version Repo Size ================================================================================ Installing: java-1.8.0-openjdk-devel aarch64 1:1.8.0.362.b01-0.3.ea.el9 appstream 9.3 M Installing dependencies: copy-jdk-configs noarch 4.0-3.el9 appstream 28 k ibus-gtk2 aarch64 1.5.25-2.el9 appstream 27 k java-1.8.0-openjdk aarch64 1:1.8.0.362.b01-0.3.ea.el9 appstream 456 k java-1.8.0-openjdk-headless aarch64 1:1.8.0.362.b01-0.3.ea.el9 appstream 33 M javapackages-filesystem noarch 6.0.0-3.el9 appstream 14 k lksctp-tools aarch64 1.0.19-2.el9 baseos 93 k lua aarch64 5.4.2-7.el9 appstream 185 k lua-posix aarch64 35.0-8.el9 appstream 149 k mkfontscale aarch64 1.2.1-3.el9 appstream 32 k ttmkfdir aarch64 3.0.9-65.el9 appstream 51 k tzdata-java noarch 2022g-2.el9 appstream 229 k xorg-x11-fonts-Type1 noarch 7.5-33.el9 appstream 505 k Installing weak dependencies: adwaita-gtk2-theme aarch64 3.28-14.el9 appstream 213 k gtk2 aarch64 2.24.33-8.el9 appstream 3.4 M libcanberra-gtk2 aarch64 0.30-26.el9 appstream 25 k Transaction Summary ================================================================================ Install 16 Packages Total download size: 48 M Installed size: 182 M ##### snipped
- Verify the installed javac version.
$ javac -version javac 1.8.0_362-ea
- Install additional OpenJDK versions if required.
$ sudo dnf install --assumeyes java-17-openjdk-devel [sudo] password for user: Last metadata expiration check: 0:04:43 ago on Thu 26 Jan 2023 03:32:34 PM +08. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: java-17-openjdk-devel aarch64 1:17.0.6.0.9-0.3.ea.el9 appstream 4.7 M Installing dependencies: java-17-openjdk aarch64 1:17.0.6.0.9-0.3.ea.el9 appstream 430 k java-17-openjdk-headless aarch64 1:17.0.6.0.9-0.3.ea.el9 appstream 41 M Transaction Summary ================================================================================ Install 3 Packages Total download size: 46 M Installed size: 206 M ##### snipped
- Set the default javac version if multiple versions are installed.
$ sudo alternatives --config javac There are 2 programs which provide 'javac'. Selection Command ----------------------------------------------- *+ 1 java-1.8.0-openjdk.aarch64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b01-0.3.ea.el9.aarch64/bin/javac) 2 java-17-openjdk.aarch64 (/usr/lib/jvm/java-17-openjdk-17.0.6.0.9-0.3.ea.el9.aarch64/bin/javac) Enter to keep the current selection[+], or type selection number: 2
- Verify the default JDK version.
$ javac -version javac 17.0.6-ea
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.