In this tutorial, you will learn how to install OpenJDK 11 on CentOS 7. Oracle JDK includes compiler but compiler for OpenJDK 11 is included in openjdk-devel. OpenJDK is an open-source implementation of the Java Platform, OpenJDK comes under Standard Edition licensed – GNU General Public License version 2.
Prerequisites
- Access to CentOS machine with root/sudo privileges
- Need YUM package manager to install OpenJDK package
Steps to Install OpenJDK 11 On CentOS 7
Step 1: Install OpenJDK 11 on CentOS 7
yum -y install java-11-openjdk java-11-openjdk-devel
cat > /etc/profile.d/java11.sh <<EOF export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac))))) EOF
Add below lines in ~/.bash_profile.
To add JAVA_HOME path in bash_profile, run below command. If you are running the application with the other user then run below command by switching to that user.
echo "export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))" >> ~/.bash_profile
source ~/.bash_profile
Sample output:
[root@centos-7 ~]# yum -y install java-11-openjdk java-11-openjdk-devel Loaded plugins: fastestmirror Determining fastest mirrors * base: mirror.tino.org * extras: mirror.tino.org * updates: mirror.tino.org base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/4): base/7/x86_64/group_gz | 153 kB 00:00:01 (2/4): extras/7/x86_64/primary_db | 222 kB 00:00:02 (3/4): updates/7/x86_64/primary_db | 3.7 MB 00:00:05 (4/4): base/7/x86_64/primary_db | 6.1 MB 00:00:10 Resolving Dependencies --> Running transaction check ---> Package java-11-openjdk.x86_64 1:11.0.9.11-0.el7_9 will be installed --> Processing Dependency: java-11-openjdk-headless(x86-64) = 1:11.0.9.11-0.el7_9 for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: xorg-x11-fonts-Type1 for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libjpeg.so.62(LIBJPEG_6.2)(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: fontconfig(x86-64) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libjvm.so()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libjpeg.so.62()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libjava.so()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libgif.so.4()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libXtst.so.6()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libXrender.so.1()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libXi.so.6()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libXext.so.6()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libX11.so.6()(64bit) for package: 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 ---> Package java-11-openjdk-devel.x86_64 1:11.0.9.11-0.el7_9 will be installed --> Running transaction check ---> Package fontconfig.x86_64 0:2.13.0-4.3.el7 will be installed --> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.13.0-4.3.el7.x86_64 --> Processing Dependency: dejavu-sans-fonts for package: fontconfig-2.13.0-4.3.el7.x86_64 ---> Package giflib.x86_64 0:4.1.6-9.el7 will be installed --> Processing Dependency: libSM.so.6()(64bit) for package: giflib-4.1.6-9.el7.x86_64 --> Processing Dependency: libICE.so.6()(64bit) for package: giflib-4.1.6-9.el7.x86_64 ---> Package java-11-openjdk-headless.x86_64 1:11.0.9.11-0.el7_9 will be installed --> Processing Dependency: tzdata-java >= 2020a for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: copy-jdk-configs >= 3.3 for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: pcsc-lite-libs(x86-64) for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: lksctp-tools(x86-64) for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libasound.so.2(ALSA_0.9.0rc4)(64bit) for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libasound.so.2(ALSA_0.9)(64bit) for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: javapackages-tools for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: cups-libs(x86-64) for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 --> Processing Dependency: libasound.so.2()(64bit) for package: 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 ---> Package libX11.x86_64 0:1.6.7-3.el7_9 will be installed --> Processing Dependency: libX11-common >= 1.6.7-3.el7_9 for package: libX11-1.6.7-3.el7_9.x86_64 --> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.7-3.el7_9.x86_64 ---> Package libXext.x86_64 0:1.3.3-3.el7 will be installed ---> Package libXi.x86_64 0:1.7.9-1.el7 will be installed ---> Package libXrender.x86_64 0:0.9.10-1.el7 will be installed ---> Package libXtst.x86_64 0:1.2.3-1.el7 will be installed ---> Package libjpeg-turbo.x86_64 0:1.2.90-8.el7 will be installed ---> Package xorg-x11-fonts-Type1.noarch 0:7.5-9.el7 will be installed --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.5-9.el7.noarch --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.5-9.el7.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.5-9.el7.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.5-9.el7.noarch --> Running transaction check ---> Package alsa-lib.x86_64 0:1.1.8-1.el7 will be installed ---> Package copy-jdk-configs.noarch 0:3.3-10.el7_5 will be installed ---> Package cups-libs.x86_64 1:1.6.3-51.el7 will be installed --> Processing Dependency: libavahi-common.so.3()(64bit) for package: 1:cups-libs-1.6.3-51.el7.x86_64 --> Processing Dependency: libavahi-client.so.3()(64bit) for package: 1:cups-libs-1.6.3-51.el7.x86_64 ---> Package dejavu-sans-fonts.noarch 0:2.33-6.el7 will be installed --> Processing Dependency: dejavu-fonts-common = 2.33-6.el7 for package: dejavu-sans-fonts-2.33-6.el7.noarch ---> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed ---> Package javapackages-tools.noarch 0:3.4.1-11.el7 will be installed --> Processing Dependency: python-javapackages = 3.4.1-11.el7 for package: javapackages-tools-3.4.1-11.el7.noarch --> Processing Dependency: libxslt for package: javapackages-tools-3.4.1-11.el7.noarch ---> Package libICE.x86_64 0:1.0.9-9.el7 will be installed ---> Package libSM.x86_64 0:1.2.2-2.el7 will be installed ---> Package libX11-common.noarch 0:1.6.7-3.el7_9 will be installed ---> Package libxcb.x86_64 0:1.13-1.el7 will be installed --> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.13-1.el7.x86_64 ---> Package lksctp-tools.x86_64 0:1.0.17-2.el7 will be installed ---> Package pcsc-lite-libs.x86_64 0:1.8.8-8.el7 will be installed ---> Package ttmkfdir.x86_64 0:3.0.9-42.el7 will be installed ---> Package tzdata-java.noarch 0:2020d-2.el7 will be installed ---> Package xorg-x11-font-utils.x86_64 1:7.5-21.el7 will be installed --> Processing Dependency: libfontenc.so.1()(64bit) for package: 1:xorg-x11-font-utils-7.5-21.el7.x86_64 --> Running transaction check ---> Package avahi-libs.x86_64 0:0.6.31-20.el7 will be installed ---> Package dejavu-fonts-common.noarch 0:2.33-6.el7 will be installed ---> Package libXau.x86_64 0:1.0.8-2.1.el7 will be installed ---> Package libfontenc.x86_64 0:1.1.3-3.el7 will be installed ---> Package libxslt.x86_64 0:1.1.28-6.el7 will be installed ---> Package python-javapackages.noarch 0:3.4.1-11.el7 will be installed --> Processing Dependency: python-lxml for package: python-javapackages-3.4.1-11.el7.noarch --> Running transaction check ---> Package python-lxml.x86_64 0:3.2.1-4.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================== Package Arch Version Repository Size ======================================================================================================================== Installing: java-11-openjdk x86_64 1:11.0.9.11-0.el7_9 updates 224 k java-11-openjdk-devel x86_64 1:11.0.9.11-0.el7_9 updates 3.4 M Installing for dependencies: alsa-lib x86_64 1.1.8-1.el7 base 425 k avahi-libs x86_64 0.6.31-20.el7 base 62 k copy-jdk-configs noarch 3.3-10.el7_5 base 21 k cups-libs x86_64 1:1.6.3-51.el7 base 359 k dejavu-fonts-common noarch 2.33-6.el7 base 64 k dejavu-sans-fonts noarch 2.33-6.el7 base 1.4 M fontconfig x86_64 2.13.0-4.3.el7 base 254 k fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k giflib x86_64 4.1.6-9.el7 base 40 k java-11-openjdk-headless x86_64 1:11.0.9.11-0.el7_9 updates 39 M javapackages-tools noarch 3.4.1-11.el7 base 73 k libICE x86_64 1.0.9-9.el7 base 66 k libSM x86_64 1.2.2-2.el7 base 39 k libX11 x86_64 1.6.7-3.el7_9 updates 607 k libX11-common noarch 1.6.7-3.el7_9 updates 164 k libXau x86_64 1.0.8-2.1.el7 base 29 k libXext x86_64 1.3.3-3.el7 base 39 k libXi x86_64 1.7.9-1.el7 base 40 k libXrender x86_64 0.9.10-1.el7 base 26 k libXtst x86_64 1.2.3-1.el7 base 20 k libfontenc x86_64 1.1.3-3.el7 base 31 k libjpeg-turbo x86_64 1.2.90-8.el7 base 135 k libxcb x86_64 1.13-1.el7 base 214 k libxslt x86_64 1.1.28-6.el7 base 242 k lksctp-tools x86_64 1.0.17-2.el7 base 88 k pcsc-lite-libs x86_64 1.8.8-8.el7 base 34 k python-javapackages noarch 3.4.1-11.el7 base 31 k python-lxml x86_64 3.2.1-4.el7 base 758 k ttmkfdir x86_64 3.0.9-42.el7 base 48 k tzdata-java noarch 2020d-2.el7 updates 189 k xorg-x11-font-utils x86_64 1:7.5-21.el7 base 104 k xorg-x11-fonts-Type1 noarch 7.5-9.el7 base 521 k Transaction Summary ====================================================================================================================== Install 2 Packages (+32 Dependent packages) Total download size: 49 M Installed size: 188 M Downloading packages: warning: /var/cache/yum/x86_64/7/base/packages/copy-jdk-configs-3.3-10.el7_5.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY B --:--:-- ETA Public key for copy-jdk-configs-3.3-10.el7_5.noarch.rpm is not installed (1/34): copy-jdk-configs-3.3-10.el7_5.noarch.rpm | 21 kB 00:00:00 (2/34): dejavu-fonts-common-2.33-6.el7.noarch.rpm | 64 kB 00:00:00 (3/34): avahi-libs-0.6.31-20.el7.x86_64.rpm | 62 kB 00:00:01 (4/34): cups-libs-1.6.3-51.el7.x86_64.rpm | 359 kB 00:00:01 (5/34): alsa-lib-1.1.8-1.el7.x86_64.rpm | 425 kB 00:00:01 (6/34): fontpackages-filesystem-1.44-8.el7.noarch.rpm | 9.9 kB 00:00:00 (7/34): fontconfig-2.13.0-4.3.el7.x86_64.rpm | 254 kB 00:00:00 (8/34): giflib-4.1.6-9.el7.x86_64.rpm | 40 kB 00:00:00 (9/34): javapackages-tools-3.4.1-11.el7.noarch.rpm | 73 kB 00:00:00 Public key for java-11-openjdk-11.0.9.11-0.el7_9.x86_64.rpm is not installed (10/34): java-11-openjdk-11.0.9.11-0.el7_9.x86_64.rpm | 224 kB 00:00:01 (11/34): libICE-1.0.9-9.el7.x86_64.rpm | 66 kB 00:00:00 (12/34): libSM-1.2.2-2.el7.x86_64.rpm | 39 kB 00:00:00 (13/34): dejavu-sans-fonts-2.33-6.el7.noarch.rpm | 1.4 MB 00:00:02 (14/34): libXau-1.0.8-2.1.el7.x86_64.rpm | 29 kB 00:00:00 (15/34): libXext-1.3.3-3.el7.x86_64.rpm | 39 kB 00:00:00 (16/34): libXi-1.7.9-1.el7.x86_64.rpm | 40 kB 00:00:00 (17/34): libXrender-0.9.10-1.el7.x86_64.rpm | 26 kB 00:00:00 (18/34): libXtst-1.2.3-1.el7.x86_64.rpm | 20 kB 00:00:00 (19/34): libX11-common-1.6.7-3.el7_9.noarch.rpm | 164 kB 00:00:01 (20/34): libfontenc-1.1.3-3.el7.x86_64.rpm | 31 kB 00:00:00 (21/34): libjpeg-turbo-1.2.90-8.el7.x86_64.rpm | 135 kB 00:00:00 (22/34): libxslt-1.1.28-6.el7.x86_64.rpm | 242 kB 00:00:01 (23/34): libxcb-1.13-1.el7.x86_64.rpm | 214 kB 00:00:02 (24/34): lksctp-tools-1.0.17-2.el7.x86_64.rpm | 88 kB 00:00:00 (25/34): python-javapackages-3.4.1-11.el7.noarch.rpm | 31 kB 00:00:00 (26/34): pcsc-lite-libs-1.8.8-8.el7.x86_64.rpm | 34 kB 00:00:00 (27/34): ttmkfdir-3.0.9-42.el7.x86_64.rpm | 48 kB 00:00:00 (28/34): tzdata-java-2020d-2.el7.noarch.rpm | 189 kB 00:00:01 (29/34): libX11-1.6.7-3.el7_9.x86_64.rpm | 607 kB 00:00:07 (30/34): python-lxml-3.2.1-4.el7.x86_64.rpm | 758 kB 00:00:03 (31/34): xorg-x11-font-utils-7.5-21.el7.x86_64.rpm | 104 kB 00:00:00 (32/34): xorg-x11-fonts-Type1-7.5-9.el7.noarch.rpm | 521 kB 00:00:04 (33/34): java-11-openjdk-devel-11.0.9.11-0.el7_9.x86_64.rpm | 3.4 MB 00:00:17 (34/34): java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64.rpm | 39 MB 00:00:07 ---------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 495 kB/s | 49 MB 00:01:40 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libxslt-1.1.28-6.el7.x86_64 1/34 Installing : libjpeg-turbo-1.2.90-8.el7.x86_64 2/34 Installing : fontpackages-filesystem-1.44-8.el7.noarch 3/34 Installing : libICE-1.0.9-9.el7.x86_64 4/34 Installing : libSM-1.2.2-2.el7.x86_64 5/34 Installing : dejavu-fonts-common-2.33-6.el7.noarch 6/34 Installing : dejavu-sans-fonts-2.33-6.el7.noarch 7/34 Installing : fontconfig-2.13.0-4.3.el7.x86_64 8/34 Installing : python-lxml-3.2.1-4.el7.x86_64 9/34 Installing : python-javapackages-3.4.1-11.el7.noarch 10/34 Installing : javapackages-tools-3.4.1-11.el7.noarch 11/34 Installing : avahi-libs-0.6.31-20.el7.x86_64 12/34 Installing : 1:cups-libs-1.6.3-51.el7.x86_64 13/34 Installing : copy-jdk-configs-3.3-10.el7_5.noarch 14/34 Installing : libfontenc-1.1.3-3.el7.x86_64 15/34 Installing : 1:xorg-x11-font-utils-7.5-21.el7.x86_64 16/34 Installing : libXau-1.0.8-2.1.el7.x86_64 17/34 Installing : libxcb-1.13-1.el7.x86_64 18/34 Installing : tzdata-java-2020d-2.el7.noarch 19/34 Installing : pcsc-lite-libs-1.8.8-8.el7.x86_64 20/34 Installing : libX11-common-1.6.7-3.el7_9.noarch 21/34 Installing : libX11-1.6.7-3.el7_9.x86_64 22/34 Installing : libXext-1.3.3-3.el7.x86_64 23/34 Installing : libXi-1.7.9-1.el7.x86_64 24/34 Installing : libXtst-1.2.3-1.el7.x86_64 25/34 Installing : giflib-4.1.6-9.el7.x86_64 26/34 Installing : libXrender-0.9.10-1.el7.x86_64 27/34 Installing : lksctp-tools-1.0.17-2.el7.x86_64 28/34 Installing : alsa-lib-1.1.8-1.el7.x86_64 29/34 Installing : 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 30/34 Installing : ttmkfdir-3.0.9-42.el7.x86_64 31/34 Installing : xorg-x11-fonts-Type1-7.5-9.el7.noarch 32/34 Installing : 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 33/34 Installing : 1:java-11-openjdk-devel-11.0.9.11-0.el7_9.x86_64 34/34 Verifying : libXext-1.3.3-3.el7.x86_64 1/34 Verifying : libXi-1.7.9-1.el7.x86_64 2/34 Verifying : fontconfig-2.13.0-4.3.el7.x86_64 3/34 Verifying : giflib-4.1.6-9.el7.x86_64 4/34 Verifying : libXrender-0.9.10-1.el7.x86_64 5/34 Verifying : 1:java-11-openjdk-11.0.9.11-0.el7_9.x86_64 6/34 Verifying : python-lxml-3.2.1-4.el7.x86_64 7/34 Verifying : libICE-1.0.9-9.el7.x86_64 8/34 Verifying : fontpackages-filesystem-1.44-8.el7.noarch 9/34 Verifying : ttmkfdir-3.0.9-42.el7.x86_64 10/34 Verifying : 1:cups-libs-1.6.3-51.el7.x86_64 11/34 Verifying : alsa-lib-1.1.8-1.el7.x86_64 12/34 Verifying : 1:java-11-openjdk-devel-11.0.9.11-0.el7_9.x86_64 13/34 Verifying : python-javapackages-3.4.1-11.el7.noarch 14/34 Verifying : 1:java-11-openjdk-headless-11.0.9.11-0.el7_9.x86_64 15/34 Verifying : dejavu-fonts-common-2.33-6.el7.noarch 16/34 Verifying : libXtst-1.2.3-1.el7.x86_64 17/34 Verifying : libxcb-1.13-1.el7.x86_64 18/34 Verifying : lksctp-tools-1.0.17-2.el7.x86_64 19/34 Verifying : libjpeg-turbo-1.2.90-8.el7.x86_64 20/34 Verifying : xorg-x11-fonts-Type1-7.5-9.el7.noarch 21/34 Verifying : libX11-common-1.6.7-3.el7_9.noarch 22/34 Verifying : libX11-1.6.7-3.el7_9.x86_64 23/34 Verifying : dejavu-sans-fonts-2.33-6.el7.noarch 24/34 Verifying : pcsc-lite-libs-1.8.8-8.el7.x86_64 25/34 Verifying : javapackages-tools-3.4.1-11.el7.noarch 26/34 Verifying : tzdata-java-2020d-2.el7.noarch 27/34 Verifying : libXau-1.0.8-2.1.el7.x86_64 28/34 Verifying : libSM-1.2.2-2.el7.x86_64 29/34 Verifying : libxslt-1.1.28-6.el7.x86_64 30/34 Verifying : 1:xorg-x11-font-utils-7.5-21.el7.x86_64 31/34 Verifying : libfontenc-1.1.3-3.el7.x86_64 32/34 Verifying : copy-jdk-configs-3.3-10.el7_5.noarch 33/34 Verifying : avahi-libs-0.6.31-20.el7.x86_64 34/34 Installed: java-11-openjdk.x86_64 1:11.0.9.11-0.el7_9 java-11-openjdk-devel.x86_64 1:11.0.9.11-0.el7_9 Dependency Installed: alsa-lib.x86_64 0:1.1.8-1.el7 avahi-libs.x86_64 0:0.6.31-20.el7 copy-jdk-configs.noarch 0:3.3-10.el7_5 cups-libs.x86_64 1:1.6.3-51.el7 dejavu-fonts-common.noarch 0:2.33-6.el7 dejavu-sans-fonts.noarch 0:2.33-6.el7 fontconfig.x86_64 0:2.13.0-4.3.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 giflib.x86_64 0:4.1.6-9.el7 java-11-openjdk-headless.x86_64 1:11.0.9.11-0.el7_9 javapackages-tools.noarch 0:3.4.1-11.el7 libICE.x86_64 0:1.0.9-9.el7 libSM.x86_64 0:1.2.2-2.el7 libX11.x86_64 0:1.6.7-3.el7_9 libX11-common.noarch 0:1.6.7-3.el7_9 libXau.x86_64 0:1.0.8-2.1.el7 libXext.x86_64 0:1.3.3-3.el7 libXi.x86_64 0:1.7.9-1.el7 libXrender.x86_64 0:0.9.10-1.el7 libXtst.x86_64 0:1.2.3-1.el7 libfontenc.x86_64 0:1.1.3-3.el7 libjpeg-turbo.x86_64 0:1.2.90-8.el7 libxcb.x86_64 0:1.13-1.el7 libxslt.x86_64 0:1.1.28-6.el7 lksctp-tools.x86_64 0:1.0.17-2.el7 pcsc-lite-libs.x86_64 0:1.8.8-8.el7 python-javapackages.noarch 0:3.4.1-11.el7 python-lxml.x86_64 0:3.2.1-4.el7 ttmkfdir.x86_64 0:3.0.9-42.el7 tzdata-java.noarch 0:2020d-2.el7 xorg-x11-font-utils.x86_64 1:7.5-21.el7 xorg-x11-fonts-Type1.noarch 0:7.5-9.el7 Complete! [root@centos-7 ~]# [root@centos-7 ~]# [root@centos-7 ~]# echo "export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))" >> ~/.bash_profile [root@centos-7 ~]# [root@centos-7 ~]# cat ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.9.11-0.el7_9.x86_64 [root@centos-7 ~]#
Step 2: Verify Java Version
# java –version
# echo $JAVA_HOME
Sample Output:
[root@centos-7 ~]# java --version openjdk 11.0.9 2020-10-20 LTS OpenJDK Runtime Environment 18.9 (build 11.0.9+11-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.9+11-LTS, mixed mode, sharing) [root@centos-7 ~]# [root@centos-7 ~]# echo $JAVA_HOME [root@centos-7 ~]# source ~/.bash_profile [root@centos-7 ~]# [root@centos-7 ~]# echo $JAVA_HOME /usr/lib/jvm/java-11-openjdk-11.0.9.11-0.el7_9.x86_64 [root@centos-7 ~]#
Step 3: Set or configure default Java version on CentOS 7
If there is another/old version already installed then follow the below steps:
Run below command and set the default Java version.
# alternatives –config java
Sample output:
[root@centos-7 ~]# alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.9.11-0.el7_9.x86_64/bin/java) *+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.272.b10-1.el7_9.x86_64/jre/bin/java) Enter to keep the current selection[+], or type selection number: 1 [root@centos-7 ~]#
Step 4: Set default Javac on CentOS 7
Run below command and follow below steps
# alternatives –config javac
Sample Output:
[root@centos-7 ~]# alternatives --config javac There is 1 program that provides 'javac'. Selection Command ----------------------------------------------- *+ 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.9.11-0.el7_9.x86_64/bin/javac) Enter to keep the current selection[+], or type selection number: 1 [root@centos-7 ~]#
Step 5: Test Java Installation on CentOS 7
Test Java Installation on Centos 7 with the help of below sample Java code.
cat > hello_world.java <<EOF public class helloworld { public static void main(String[] args) { System.out.println("Hello Java World!"); } } EOF
Run above Java code and this should print “Hello Java World!” on your CentOS terminal.
$ java hello_world.java
Hello Java World!
Sample Output:
[root@centos-7 ~]# cat > hello_world.java <<EOF > public class helloworld { > public static void main(String[] args) { > System.out.println("Hello Java World!"); > } > } > EOF [root@centos-7 ~]# java hello_world.java Hello Java World! [root@centos-7 ~]#
How to Uninstall Java on CentOS 7
If you want to remove old Java version then follow below command.
In my case old Java version is 1.8v.
sudo yum remove java-1.8.0-openjdk java-1.8.0-openjdk-devel
Sample Output:
[root@centos-7 ~]# yum remove java-1.8.0-openjdk java-1.8.0-openjdk-devel Loaded plugins: fastestmirror No Match for argument: java-1.8.0-openjdk-devel Resolving Dependencies --> Running transaction check ---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.272.b10-1.el7_9 will be erased --> Finished Dependency Resolution Dependencies Resolved =================================================================================================== Package Arch Version Repository Size =================================================================================================== Removing: java-1.8.0-openjdk x86_64 1:1.8.0.272.b10-1.el7_9 @updates 646 k Transaction Summary =================================================================================================== Remove 1 Package Installed size: 646 k Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : 1:java-1.8.0-openjdk-1.8.0.272.b10-1.el7_9.x86_64 1/1 Verifying : 1:java-1.8.0-openjdk-1.8.0.272.b10-1.el7_9.x86_64 1/1 Removed: java-1.8.0-openjdk.x86_64 1:1.8.0.272.b10-1.el7_9 Complete! [root@centos-7 ~]#
This is the End of the tutorial, you have learned how to install OpenJDK 11 on CentOS 7.
FAQs:
Q1: What is OpenJDK?
A1: OpenJDK is an open-source implementation of the Java Platform, Standard Edition (Java SE). It serves as the reference implementation for the Java programming language.
Q2: Why use OpenJDK 11?
A2: OpenJDK 11 is a long-term support (LTS) release, providing stability and security updates. It’s suitable for applications that require a stable and well-supported Java version.
Q3: Can I install multiple Java versions on CentOS 7?
A3: Yes, you can install multiple Java versions on CentOS 7 and use the alternatives
command to switch between them.
Q4: How do I uninstall OpenJDK 11 from CentOS 7?
A4: To uninstall OpenJDK 11, you can use the following command:
sudo yum remove java-11-openjdk
Q5: Is OpenJDK free to use?
A5: Yes, OpenJDK is free and open-source software distributed under the GNU General Public License (GPL), making it free to use for both development and production.
These FAQs provide additional information and answers to common questions about installing OpenJDK 11 on CentOS 7.
See Also:
Steps to Upgrade Java 8 to Java 11 on CentOS 7
After make this:
cat > /etc/profile.d/java11.sh <<EOF
export JAVA_HOME=\$(dirname \$(dirname \$(readlink \$(readlink \$(which javac)))))
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar
EOF
Can't use my bash anymore:
$ source /etc/profile.d/java11.sh
bash: sed: no se encontró la orden…
After installing OpenJDK 11, I run below command and it works:
echo “export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))” >> ~/.bash_profile
source ~/.bash_profile
I think you need to fix ~/.bash_profile then bash will work. (revert all changes which you have done recently)
What if I get “No package java-11-openjdk available” message ? I’m on CentOS 7.4
If you receive the message “No package java-11-openjdk available” on CentOS 7.4, it means that the OpenJDK 11 package is not available in yum repository. Try with EPEL repository below steps.
To install OpenJDK 11 on CentOS 7.4, you can use the following steps:
Enable the EPEL repository:
sudo yum install epel-release
Install OpenJDK 11:
sudo yum install java-11-openjdk-devel
Verify that Java 11 is installed correctly:
java -version
This should show you the version of Java that you just installed.
Alternatively, you can download and install OpenJDK 11 from the official OpenJDK website.
1. How to Install EPEL Repository on RHEL or Rocky or AlmaLinux
2. Install EPEL Repository on CentOS or RHEL or Amazon Linux