Table of Contents
In this article, I will take you through the steps to install Java on RHEL 8/CentOS 8. As you might be aware, Java is the most popular and powerful language currently used by Developers and Programmers for Application development on almost all the Hardware Platforms. It is Known as Platform independent Language. It uses an underlying Java Runtime Environment(JRE) to run all the java based applications on it. Java has very rich support of API Libraries which makes it compatible with other programming Languages. Here, we will look into the detailed steps required to install Java packages on RHEL 8/CentOS 8 Servers. You can check Java Official Website for more information.
Steps to Install Java on RHEL 8/CentOS 8
Also Read: Best Explanation of Wrapper Classes in Java: Autoboxing and Unboxing with Examples
Step 1: Prerequisites
a) You need to have a running RHEL 8/CentOS 8
System.
b) You should have dnf
tool installed in your Server. You can check 31 Useful DNF Command Examples for RPM Package Management in Fedora/RHEL/CentOS to know more about dnf
command.
c) You need to have root
or sudo
access to run privileged commands. Please Check How to Add User to Sudoers to know more about providing sudo
access to the User.
Step 2: Update Your Server
Before going through the steps to Install Java on RHEL 8/CentOS 8 Server, it is always recommended to update your Server with the latest available updates using dnf update -y
command as shown below. This command will download and install all the latest updates available from Enabled Repositories.
[root@localhost ~]# dnf update -y Last metadata expiration check: 0:20:52 ago on Thu 08 Oct 2020 12:56:07 PM EDT. Dependencies resolved. ======================================================================================================================================================================== Package Architecture Version Repository Size ======================================================================================================================================================================== Installing: kernel-core x86_64 4.18.0-193.19.1.el8_2 BaseOS 28 M Upgrading: alsa-lib x86_64 1.2.1.2-3.el8 AppStream 441 k bind-libs x86_64 32:9.11.13-6.el8_2.1 AppStream 172 k bind-libs-lite x86_64 32:9.11.13-6.el8_2.1 AppStream 1.2 M bind-license noarch 32:9.11.13-6.el8_2.1 AppStream 101 k bind-utils x86_64 32:9.11.13-6.el8_2.1 AppStream 443 k container-selinux noarch 2:2.124.0-1.module_el8.2.0+305+5e198a41 AppStream 47 k containers-common x86_64 1:0.1.40-11.module_el8.2.0+377+92552693 AppStream 50 k fribidi x86_64 1.0.4-8.el8 AppStream 89 k fuse-overlayfs x86_64 0.7.2-5.module_el8.2.0+305+5e198a41 AppStream 60 k git x86_64 2.18.4-2.el8_2 AppStream 186 k git-core x86_64 2.18.4-2.el8_2 AppStream 4.0 M git-core-doc noarch 2.18.4-2.el8_2 AppStream 2.3 M gtk-update-icon-cache x86_64 3.22.30-5.el8 AppStream 32 k gtk3 x86_64 3.22.30-5.el8 AppStream 4.5 M httpd x86_64 2.4.37-21.module_el8.2.0+494+1df74eae AppStream 1.7 M httpd-filesystem noarch 2.4.37-21.module_el8.2.0+494+1df74eae AppStream 36 k httpd-tools x86_64 2.4.37-21.module_el8.2.0+494+1df74eae AppStream 103 k java-1.8.0-openjdk-headless x86_64 1:1.8.0.265.b01-0.el8_2 AppStream 34 M java-11-openjdk x86_64 1:11.0.8.10-0.el8_2 AppStream 249 k java-11-openjdk-devel x86_64 1:11.0.8.10-0.el8_2 AppStream 3.4 M java-11-openjdk-headless x86_64 1:11.0.8.10-0.el8_2 AppStream 40 M libdrm x86_64 2.4.100-1.el8 AppStream 164 k libepoxy x86_64 1.5.3-1.el8 AppStream 225 k libmaxminddb x86_64 1.2.0-7.el8 AppStream 25 k libtiff x86_64 4.0.9-17.el8 AppStream 188 k libvncserver x86_64 0.9.11-15.el8_2.1 AppStream 275 k libwayland-client x86_64 1.17.0-1.el8 AppStream 39 k libwayland-cursor x86_64 1.17.0-1.el8 AppStream 26 k libwayland-egl x86_64 1.17.0-1.el8 AppStream 19 k libxcb x86_64 1.13.1-1.el8 AppStream 229 k libxkbcommon x86_64 0.9.1-1.el8 AppStream 116 k mod_http2 x86_64 1.11.3-3.module_el8.2.0+486+c01050f0.1 AppStream 156 k mod_ssl x86_64 1:2.4.37-21.module_el8.2.0+494+1df74eae AppStream 132 k nodejs x86_64 1:10.21.0-3.module_el8.2.0+391+8da3adc6 AppStream 8.9 M nodejs-docs noarch 1:10.21.0-3.module_el8.2.0+391+8da3adc6 AppStream 3.5 M nodejs-full-i18n x86_64 1:10.21.0-3.module_el8.2.0+391+8da3adc6 AppStream 7.3 M npm x86_64 1:6.14.4-1.10.21.0.3.module_el8.2.0+391+8da3adc6 AppStream 3.8 M nspr x86_64 4.25.0-2.el8_2 AppStream 142 k nss x86_64 3.53.1-11.el8_2 AppStream 721 k nss-softokn x86_64 3.53.1-11.el8_2 AppStream 484 k nss-softokn-freebl x86_64 3.53.1-11.el8_2 AppStream 289 k nss-sysinit x86_64 3.53.1-11.el8_2 AppStream 71 k nss-tools x86_64 3.53.1-11.el8_2 AppStream 559 k nss-util x86_64 3.53.1-11.el8_2 AppStream 135 k perl-Git noarch 2.18.4-2.el8_2 AppStream 77 k perl-IO-Socket-SSL noarch 2.066-4.el8 AppStream 297 k pixman x86_64 0.38.4-1.el8 AppStream 257 k plymouth x86_64 0.9.3-16.el8 AppStream 114 k plymouth-core-libs x86_64 0.9.3-16.el8 AppStream 115 k plymouth-scripts x86_64 0.9.3-16.el8 AppStream 42 k python2 x86_64 2.7.17-1.module_el8.2.0+381+9a5b3c3b AppStream 108 k python2-libs x86_64 2.7.17-1.module_el8.2.0+381+9a5b3c3b AppStream 6.0 M python2-pip noarch 9.0.3-16.module_el8.2.0+381+9a5b3c3b AppStream 1.9 M python2-pip-wheel noarch 9.0.3-16.module_el8.2.0+381+9a5b3c3b AppStream 1.2 M python2-setuptools noarch 39.0.1-11.module_el8.2.0+381+9a5b3c3b AppStream 643 k
Step 3: Install Java on RHEL 8/CentOS 8
After successfully updating the Server you can install Java 11 packages using dnf install java-11-openjdk-devel -y
command as shown below.
[root@localhost ~]# dnf install java-11-openjdk-devel -y Last metadata expiration check: 0:07:42 ago on Thu 08 Oct 2020 02:32:00 PM EDT. Dependencies resolved. ======================================================================================================================================================================== Package Architecture Version Repository Size ======================================================================================================================================================================== Installing: java-11-openjdk-devel x86_64 1:11.0.8.10-0.el8_2 AppStream 3.4 M Upgrading: java-11-openjdk-headless x86_64 1:11.0.8.10-0.el8_2 AppStream 40 M Installing dependencies: adwaita-cursor-theme noarch 3.28.0-2.el8 AppStream 647 k adwaita-icon-theme noarch 3.28.0-2.el8 AppStream 11 M at-spi2-atk x86_64 2.26.2-1.el8 AppStream 89 k at-spi2-core x86_64 2.28.0-1.el8 AppStream 169 k atk x86_64 2.28.1-1.el8 AppStream 272 k cairo-gobject x86_64 1.15.12-3.el8 AppStream 33 k colord-libs x86_64 1.4.2-1.el8 AppStream 236 k gdk-pixbuf2-modules x86_64 2.36.12-5.el8 AppStream 109 k gtk-update-icon-cache x86_64 3.22.30-5.el8 AppStream 32 k jasper-libs x86_64 2.0.14-4.el8 AppStream 167 k java-11-openjdk x86_64 1:11.0.8.10-0.el8_2 AppStream 249 k lcms2 x86_64 2.9-2.el8 AppStream 165 k libXcursor x86_64 1.1.15-3.el8 AppStream 36 k libXrandr x86_64 1.5.1-7.el8 AppStream 33 k libepoxy x86_64 1.5.3-1.el8 AppStream 225 k rest x86_64 0.8.1-2.el8 AppStream 70 k glib-networking x86_64 2.56.1-1.1.el8 BaseOS 155 k gsettings-desktop-schemas x86_64 3.32.0-4.el8 BaseOS 632 k json-glib x86_64 1.4.4-1.el8 BaseOS 144 k libgusb x86_64 0.3.0-1.el8 BaseOS 49 k libmodman x86_64 2.0.1-17.el8 BaseOS 36 k libproxy x86_64 0.4.15-5.2.el8 BaseOS 75 k libsoup x86_64 2.62.3-1.el8 BaseOS 424 k Installing weak dependencies: dconf x86_64 0.28.0-3.el8 AppStream 109 k gtk3 x86_64 3.22.30-5.el8 AppStream 4.5 M Transaction Summary ======================================================================================================================================================================== Install 26 Packages Upgrade 1 Package Total download size: 63 M Downloading Packages: (1/27): at-spi2-atk-2.26.2-1.el8.x86_64.rpm 255 kB/s | 89 kB 00:00 (2/27): at-spi2-core-2.28.0-1.el8.x86_64.rpm 1.0 MB/s | 169 kB 00:00 (3/27): adwaita-cursor-theme-3.28.0-2.el8.noarch.rpm 923 kB/s | 647 kB 00:00 (4/27): atk-2.28.1-1.el8.x86_64.rpm 1.3 MB/s | 272 kB 00:00 (5/27): cairo-gobject-1.15.12-3.el8.x86_64.rpm 613 kB/s | 33 kB 00:00 (6/27): dconf-0.28.0-3.el8.x86_64.rpm 1.0 MB/s | 109 kB 00:00 (7/27): colord-libs-1.4.2-1.el8.x86_64.rpm 1.4 MB/s | 236 kB 00:00 (8/27): gtk-update-icon-cache-3.22.30-5.el8.x86_64.rpm 463 kB/s | 32 kB 00:00 (9/27): gdk-pixbuf2-modules-2.36.12-5.el8.x86_64.rpm 1.0 MB/s | 109 kB 00:00 (10/27): jasper-libs-2.0.14-4.el8.x86_64.rpm 700 kB/s | 167 kB 00:00 (11/27): java-11-openjdk-11.0.8.10-0.el8_2.x86_64.rpm 1.1 MB/s | 249 kB 00:00 (12/27): gtk3-3.22.30-5.el8.x86_64.rpm 3.2 MB/s | 4.5 MB 00:01 (13/27): lcms2-2.9-2.el8.x86_64.rpm 295 kB/s | 165 kB 00:00 (14/27): libXcursor-1.1.15-3.el8.x86_64.rpm 554 kB/s | 36 kB 00:00 (15/27): libXrandr-1.5.1-7.el8.x86_64.rpm 485 kB/s | 33 kB 00:00 (16/27): libepoxy-1.5.3-1.el8.x86_64.rpm 1.1 MB/s | 225 kB 00:00 (17/27): rest-0.8.1-2.el8.x86_64.rpm 935 kB/s | 70 kB 00:00 (18/27): glib-networking-2.56.1-1.1.el8.x86_64.rpm 876 kB/s | 155 kB 00:00 (19/27): gsettings-desktop-schemas-3.32.0-4.el8.x86_64.rpm 2.0 MB/s | 632 kB 00:00 (20/27): json-glib-1.4.4-1.el8.x86_64.rpm 1.1 MB/s | 144 kB 00:00 (21/27): libgusb-0.3.0-1.el8.x86_64.rpm 746 kB/s | 49 kB 00:00 (22/27): libmodman-2.0.1-17.el8.x86_64.rpm 441 kB/s | 36 kB 00:00 (23/27): libproxy-0.4.15-5.2.el8.x86_64.rpm 745 kB/s | 75 kB 00:00 (24/27): java-11-openjdk-devel-11.0.8.10-0.el8_2.x86_64.rpm 1.2 MB/s | 3.4 MB 00:02 (25/27): libsoup-2.62.3-1.el8.x86_64.rpm 1.8 MB/s | 424 kB 00:00 (26/27): adwaita-icon-theme-3.28.0-2.el8.noarch.rpm 1.3 MB/s | 11 MB 00:09 (27/27): java-11-openjdk-headless-11.0.8.10-0.el8_2.x86_64.rpm 2.7 MB/s | 40 MB 00:14 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 3.2 MB/s | 63 MB 00:19 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Running scriptlet: java-11-openjdk-headless-1:11.0.8.10-0.el8_2.x86_64 1/1 Preparing : 1/1 Installing : lcms2-2.9-2.el8.x86_64 1/28 Running scriptlet: lcms2-2.9-2.el8.x86_64 1/28 Upgrading : java-11-openjdk-headless-1:11.0.8.10-0.el8_2.x86_64 2/28
Step 4: Check Java Version
Once java is installed in your system you can check the version by using java -version command as shown below. As you can see from below output, current installed version is 1.8.0_242
.
[root@localhost ~]# java -version openjdk version "1.8.0_242" OpenJDK Runtime Environment (build 1.8.0_242-b08) OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Step 5: Write Your First Java Program
You can test the installation of Java by writing a simple Program to display "This is hello from CyberITHub!" on the output.
[root@localhost ~]# vi hello.java class hello { public static void main(String args[]) { System.out.println("This is hello from CyberITHub!"); } }
Compile Your Program
[root@localhost ~]# javac hello.java
Run Your Program
[root@localhost ~]# java hello This is hello from CyberITHub!
Popular Recommendations:-
How to Install Ruby on Ubuntu 18.04 with Easy Steps
How to Install PHP on RedHat/CentOS 7 with Easy Steps
Solved: nrpe.service: main process exited, code=exited, status=2/INVALIDARGUMENT
C# data types with Best Examples (.NET v4.7)
How to Transfer Files to an AWS EC2 Instance Using WinSCP in 3 Easy Steps
Learn HTML Image Maps(v5) with Best Examples