How to Install Java Runtime Environment on CentOS 8 - CentLinux

Latest

Wednesday, 22 January 2020

How to Install Java Runtime Environment on CentOS 8

How to Install Java Runtime Environment on CentOS 8

Java is a general purpose and object-oriented programming language. Java applications are compiled into Byte code and it only requires a Java Virtual Machine (JVM) to execute regardless of the computer architecture. That makes Java applications platform independent.

In this article, we are addressing; how to install Java runtime environment on CentOS 8.

Effective Java by Addison-Wesley Professional is a good book, if you want to start learning Java programming language.

 

This Article Provides:

     

    Environment Specification:

    We are using a virtual machine with minimally installed CentOS 8 server.

    • CPU - 3.4 Ghz (2 cores)
    • Memory - 2 GB
    • Storage - 20 GB
    • Operating System - CentOS 8
    • Hostname – java-01.sysadminlabs.com
    • IP Address - 192.168.116.206 /24

     

    Installing OpenJDK Java Runtime Environment on CentOS 8:

    OpenJDK is the free and open source implementation of Java Platform, Standard Edition (SE). OpenJDK is distributed under GNU GPL v2 license.

    Two versions of OpenJDK are available in CentOS 8 standard yum repositories. i.e. OpenJDK 8 and OpenJDK 11. Obviously, they are the open source implementations of Oracle Java SE 8 and Oracle Java SE 11.

    The installation steps are same for both versions. Here, we are installing OpenJDK 8 on our CentOS 8 server, but you can also install OpenJDK 11 by using the same steps.

    Connect with java-01.sysadminlabs.com as root user by using a ssh tool and install OpenJDK java runtime environment.

    [root@java-01 ~]# dnf install -y java-1.8.0-openjdk.x86_64 ... Upgraded: lua-libs-5.3.4-11.el8.x86_64 Installed: java-1.8.0-openjdk-1:1.8.0.232.b09-2.el8_1.x86_64 gtk2-2.24.32-4.el8.x86_64 alsa-lib-1.1.9-4.el8.x86_64 atk-2.28.1-1.el8.x86_64 cairo-1.15.12-3.el8.x86_64 copy-jdk-configs-3.7-1.el8.noarch fribidi-1.0.4-7.el8_1.x86_64 gdk-pixbuf2-modules-2.36.12-5.el8.x86_64 giflib-5.1.4-3.el8.x86_64 graphite2-1.3.10-10.el8.x86_64 gtk-update-icon-cache-3.22.30-4.el8.x86_64 harfbuzz-1.7.5-3.el8.x86_64 hicolor-icon-theme-0.17-2.el8.noarch jasper-libs-2.0.14-4.el8.x86_64 java-1.8.0-openjdk-headless-1:1.8.0.232.b09-2.el8_1.x86_64 javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch jbigkit-libs-2.1-14.el8.x86_64 libX11-1.6.7-1.el8.x86_64 libX11-common-1.6.7-1.el8.noarch libXau-1.0.8-13.el8.x86_64 libXcomposite-0.4.4-14.el8.x86_64 libXcursor-1.1.15-3.el8.x86_64 libXdamage-1.1.4-14.el8.x86_64 libXext-1.3.3-9.el8.x86_64 libXfixes-5.0.3-7.el8.x86_64 libXft-2.3.2-10.el8.x86_64 libXi-1.7.9-7.el8.x86_64 libXinerama-1.1.4-1.el8.x86_64 libXrandr-1.5.1-7.el8.x86_64 libXrender-0.9.10-7.el8.x86_64 libXtst-1.2.3-7.el8.x86_64 libdatrie-0.2.9-7.el8.x86_64 libfontenc-1.1.3-8.el8.x86_64 libjpeg-turbo-1.5.3-10.el8.x86_64 libthai-0.1.27-2.el8.x86_64 libtiff-4.0.9-15.el8.x86_64 libxcb-1.13-5.el8.x86_64 lua-5.3.4-11.el8.x86_64 pango-1.42.4-6.el8.x86_64 pixman-0.36.0-1.el8.x86_64 ttmkfdir-3.0.9-54.el8.x86_64 tzdata-java-2019c-1.el8.noarch xorg-x11-font-utils-1:7.5-40.el8.x86_64 xorg-x11-fonts-Type1-7.5-19.el8.noarch avahi-libs-0.7-19.el8.x86_64 cups-libs-1:2.2.6-28.el8.x86_64 dejavu-fonts-common-2.35-6.el8.noarch dejavu-sans-fonts-2.35-6.el8.noarch fontconfig-2.13.1-3.el8.x86_64 fontpackages-filesystem-1.44-22.el8.noarch gdk-pixbuf2-2.36.12-5.el8.x86_64 lksctp-tools-1.0.18-3.el8.x86_64 Complete!

    We have installed OpenJDK Java Runtime Environment (JRE). Similarly, we can also install Java Development Kit (JDK) by installing package java-1.8.0-openjdk-devel.x86_64.

    Define JAVA_PATH environment variable in /etc/profile file, so it can be set automatically while a login shell is initialized.

    [root@java-01 ~]# echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-2.el8_1.x86_64" >> /etc/profile

    Also set the JAVA_PATH for the current shell.

    [root@java-01 ~]# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-2.el8_1.x86_64

    Verify Java version.

    [root@java-01 ~]# java -version openjdk version "1.8.0_232" OpenJDK Runtime Environment (build 1.8.0_232-b09) OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

    OpenJDK Java runtime environment has been installed on CentOS 8.

     

    Installing Oracle Java Runtime Environment on CentOS 8:

    Oracle Java is the proprietary distribution of Java platform. Oracle Java is available in Standard (SE), Enterprise (EE) and Micro Editions (ME).

    Oracle Java SE is the default choice for most of the environments. Here, we are also installing the Oracle Java 13 SE on CentOS 8, that has been released recently.

    Oracle Java SE 13 is available to download at Oracle website.

    We are required an Oracle User Account for downloading Oracle Java SE 13. Therefore, login to Oracle website and download its RPM.

    Transfer the downloaded file to java-01.sysadminlabs.com using WinSCP.

    Connect to java-01.sysadminlabs.com as root user by using a ssh tool such as PuTTY.

    Install Oracle Java SE 13 using dnf command.

    [root@java-01 ~]# dnf install -y jdk-13.0.2_linux-x64_bin.rpm Last metadata expiration check: 0:37:24 ago on Wed 22 Jan 2020 06:57:45 PM PKT. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: jdk-13.0.2 x86_64 2000:13.0.2-ga @commandline 163 M Transaction Summary ================================================================================ Install 1 Package Total size: 163 M Installed size: 308 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : jdk-13.0.2-2000:13.0.2-ga.x86_64 1/1 Running scriptlet: jdk-13.0.2-2000:13.0.2-ga.x86_64 1/1 Verifying : jdk-13.0.2-2000:13.0.2-ga.x86_64 1/1 Installed: jdk-13.0.2-2000:13.0.2-ga.x86_64 Complete!

    Define JAVA_PATH environment variable in /etc/profile file, so it can be set automatically while a login shell is initialized.

    [root@java-01 ~]# echo "export JAVA_HOME=/usr/java/jdk-13.0.2" >> /etc/profile

    Also set the JAVA_PATH for the current shell.

    [root@java-01 ~]# export JAVA_HOME=/usr/java/jdk-13.0.2

    Verify Java version.

    [root@java-01 ~]# java -version java version "13.0.2" 2020-01-14 Java(TM) SE Runtime Environment (build 13.0.2+8) Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)

    We have successfully installed Oracle Java SE 13 on our CentOS 8 server.

     

    Using multiple Java Runtime Environments on same CentOS 8 server:

    We have installed OpenJDK Java 8 and Oracle Java SE 13 on the same CentOS 8 server.

    Both of these Java versions are available on the server, but only one is set as default java runtime environment.

    Since, we have installed Oracle Java SE 13 over OpenJDK 8. Therefore, we are now running the Oracle Java SE 13 as default java runtime environment.

    To switch to OpenJDK 8, we can use the alternatives command.

    [root@java-01 ~]# alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-2.el8_1.x86_64/jre/bin/java) *+ 2 /usr/java/jdk-13.0.2/bin/java Enter to keep the current selection[+], or type selection number: 1

    We have set the OpenJDK 8 as default Java runtime environment.

    Verify the version of Java now.

    [root@java-01 ~]# java -version openjdk version "1.8.0_232" OpenJDK Runtime Environment (build 1.8.0_232-b09) OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

    You can see that, OpenJDK 8 has been set as our default Java runtime environment.

    Installation of Java runtime environment on CentOS 8 has been completed.

    No comments:

    Post a comment