このセクションでは、OpenJDK 8 をインストールする方法について紹介します。

yum を使って、openjdk 8 をインストールします。

[root@server-1 ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.191.b12-1.el7_6 will be installed
--> Processing Dependency: java-1.8.0-openjdk-headless(x86-64) = 1:1.8.0.191.b12-1.el7_6 for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: xorg-x11-fonts-Type1 for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libjvm.so(SUNWprivate_1.1)(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libjpeg.so.62(LIBJPEG_6.2)(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libjava.so(SUNWprivate_1.1)(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: fontconfig(x86-64) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libjvm.so()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libjpeg.so.62()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libjava.so()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libgif.so.4()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libXtst.so.6()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libXrender.so.1()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libXi.so.6()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libXext.so.6()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libXcomposite.so.1()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: libX11.so.6()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.191.b12-1.el7_6 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-1.8.0-openjdk-headless.x86_64 1:1.8.0.191.b12-1.el7_6 will be installed
--> Processing Dependency: tzdata-java >= 2015d for package: 1:java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: copy-jdk-configs >= 2.2 for package: 1:java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: lksctp-tools(x86-64) for package: 1:java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_64
--> Processing Dependency: jpackage-utils for package: 1:java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_64
---> Package libX11.x86_64 0:1.6.5-2.el7 will be installed
--> Processing Dependency: libX11-common >= 1.6.5-2.el7 for package: libX11-1.6.5-2.el7.x86_64
--> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.5-2.el7.x86_64
---> Package libXcomposite.x86_64 0:0.4.4-4.1.el7 will be installed
---> 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-6.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 copy-jdk-configs.noarch 0:3.3-10.el7_5 will be installed
---> 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.5-2.el7 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 ttmkfdir.x86_64 0:3.0.9-42.el7 will be installed
---> Package tzdata-java.noarch 0:2018g-1.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 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-5.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-1.8.0-openjdk           x86_64  1:1.8.0.191.b12-1.el7_6    updates  254 k
 java-1.8.0-openjdk-devel     x86_64  1:1.8.0.191.b12-1.el7_6    updates  9.8 M
Installing for dependencies:
 copy-jdk-configs             noarch  3.3-10.el7_5               base      21 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-1.8.0-openjdk-headless  x86_64  1:1.8.0.191.b12-1.el7_6    updates   32 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.5-2.el7                base     606 k
 libX11-common                noarch  1.6.5-2.el7                base     164 k
 libXau                       x86_64  1.0.8-2.1.el7              base      29 k
 libXcomposite                x86_64  0.4.4-4.1.el7              base      22 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-6.el7               base     134 k
 libxcb                       x86_64  1.13-1.el7                 base     214 k
 libxslt                      x86_64  1.1.28-5.el7               base     242 k
 lksctp-tools                 x86_64  1.0.17-2.el7               base      88 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  2018g-1.el7                updates  185 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 (+29 Dependent packages)

Total download size: 47 M
Installed size: 160 M
Downloading packages:
(1/31): copy-jdk-configs-3.3-10.el7_5.noarch.rpm           |  21 kB   00:02     
(2/31): dejavu-fonts-common-2.33-6.el7.noarch.rpm          |  64 kB   00:02     
(3/31): giflib-4.1.6-9.el7.x86_64.rpm                      |  40 kB   00:00     
(4/31): fontpackages-filesystem-1.44-8.el7.noarch.rpm      | 9.9 kB   00:02     
(5/31): dejavu-sans-fonts-2.33-6.el7.noarch.rpm            | 1.4 MB   00:04     
(6/31): fontconfig-2.13.0-4.3.el7.x86_64.rpm               | 254 kB   00:02     
(7/31): javapackages-tools-3.4.1-11.el7.noarch.rpm         |  73 kB   00:00     
(8/31): libSM-1.2.2-2.el7.x86_64.rpm                       |  39 kB   00:00     
(9/31): libX11-1.6.5-2.el7.x86_64.rpm                      | 606 kB   00:00     
(10/31): libX11-common-1.6.5-2.el7.noarch.rpm              | 164 kB   00:00     
(11/31): libXau-1.0.8-2.1.el7.x86_64.rpm                   |  29 kB   00:00     
(12/31): java-1.8.0-openjdk-devel-1.8.0.191.b12-1.el7_6.x8 | 9.8 MB   00:05     
(13/31): libXcomposite-0.4.4-4.1.el7.x86_64.rpm            |  22 kB   00:00     
(14/31): java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64.r | 254 kB   00:05     
(15/31): libICE-1.0.9-9.el7.x86_64.rpm                     |  66 kB   00:03     
(16/31): libXext-1.3.3-3.el7.x86_64.rpm                    |  39 kB   00:00     
(17/31): libXi-1.7.9-1.el7.x86_64.rpm                      |  40 kB   00:00     
(18/31): libXrender-0.9.10-1.el7.x86_64.rpm                |  26 kB   00:00     
(19/31): libfontenc-1.1.3-3.el7.x86_64.rpm                 |  31 kB   00:00     
(20/31): libjpeg-turbo-1.2.90-6.el7.x86_64.rpm             | 134 kB   00:00     
(21/31): libxcb-1.13-1.el7.x86_64.rpm                      | 214 kB   00:00     
(22/31): libxslt-1.1.28-5.el7.x86_64.rpm                   | 242 kB   00:00     
(23/31): lksctp-tools-1.0.17-2.el7.x86_64.rpm              |  88 kB   00:00     
(24/31): python-javapackages-3.4.1-11.el7.noarch.rpm       |  31 kB   00:00     
(25/31): ttmkfdir-3.0.9-42.el7.x86_64.rpm                  |  48 kB   00:00     
(26/31): tzdata-java-2018g-1.el7.noarch.rpm                | 185 kB   00:00     
(27/31): xorg-x11-font-utils-7.5-21.el7.x86_64.rpm         | 104 kB   00:00     
(28/31): python-lxml-3.2.1-4.el7.x86_64.rpm                | 758 kB   00:01     
(29/31): xorg-x11-fonts-Type1-7.5-9.el7.noarch.rpm         | 521 kB   00:00     
(30/31): libXtst-1.2.3-1.el7.x86_64.rpm                    |  20 kB   00:02     
(31/31): java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6 |  32 MB   00:13     
--------------------------------------------------------------------------------
Total                                              2.7 MB/s |  47 MB  00:17     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libxslt-1.1.28-5.el7.x86_64                                 1/31 
  Installing : libjpeg-turbo-1.2.90-6.el7.x86_64                           2/31 
  Installing : fontpackages-filesystem-1.44-8.el7.noarch                   3/31 
  Installing : libICE-1.0.9-9.el7.x86_64                                   4/31 
  Installing : libSM-1.2.2-2.el7.x86_64                                    5/31 
  Installing : dejavu-fonts-common-2.33-6.el7.noarch                       6/31 
  Installing : dejavu-sans-fonts-2.33-6.el7.noarch                         7/31 
  Installing : fontconfig-2.13.0-4.3.el7.x86_64                            8/31 
  Installing : python-lxml-3.2.1-4.el7.x86_64                              9/31 
  Installing : python-javapackages-3.4.1-11.el7.noarch                    10/31 
  Installing : javapackages-tools-3.4.1-11.el7.noarch                     11/31 
  Installing : libfontenc-1.1.3-3.el7.x86_64                              12/31 
  Installing : 1:xorg-x11-font-utils-7.5-21.el7.x86_64                    13/31 
  Installing : tzdata-java-2018g-1.el7.noarch                             14/31 
  Installing : libX11-common-1.6.5-2.el7.noarch                           15/31 
  Installing : libXau-1.0.8-2.1.el7.x86_64                                16/31 
  Installing : libxcb-1.13-1.el7.x86_64                                   17/31 
  Installing : libX11-1.6.5-2.el7.x86_64                                  18/31 
  Installing : libXext-1.3.3-3.el7.x86_64                                 19/31 
  Installing : libXi-1.7.9-1.el7.x86_64                                   20/31 
  Installing : libXtst-1.2.3-1.el7.x86_64                                 21/31 
  Installing : giflib-4.1.6-9.el7.x86_64                                  22/31 
  Installing : libXrender-0.9.10-1.el7.x86_64                             23/31 
  Installing : libXcomposite-0.4.4-4.1.el7.x86_64                         24/31 
  Installing : lksctp-tools-1.0.17-2.el7.x86_64                           25/31 
  Installing : copy-jdk-configs-3.3-10.el7_5.noarch                       26/31 
  Installing : 1:java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_   27/31 
  Installing : ttmkfdir-3.0.9-42.el7.x86_64                               28/31 
  Installing : xorg-x11-fonts-Type1-7.5-9.el7.noarch                      29/31 
  Installing : 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64          30/31 
  Installing : 1:java-1.8.0-openjdk-devel-1.8.0.191.b12-1.el7_6.x86_64    31/31 
  Verifying  : libXext-1.3.3-3.el7.x86_64                                  1/31 
  Verifying  : libXi-1.7.9-1.el7.x86_64                                    2/31 
  Verifying  : fontconfig-2.13.0-4.3.el7.x86_64                            3/31 
  Verifying  : giflib-4.1.6-9.el7.x86_64                                   4/31 
  Verifying  : libXrender-0.9.10-1.el7.x86_64                              5/31 
  Verifying  : 1:xorg-x11-font-utils-7.5-21.el7.x86_64                     6/31 
  Verifying  : python-lxml-3.2.1-4.el7.x86_64                              7/31 
  Verifying  : libICE-1.0.9-9.el7.x86_64                                   8/31 
  Verifying  : fontpackages-filesystem-1.44-8.el7.noarch                   9/31 
  Verifying  : ttmkfdir-3.0.9-42.el7.x86_64                               10/31 
  Verifying  : libjpeg-turbo-1.2.90-6.el7.x86_64                          11/31 
  Verifying  : copy-jdk-configs-3.3-10.el7_5.noarch                       12/31 
  Verifying  : python-javapackages-3.4.1-11.el7.noarch                    13/31 
  Verifying  : dejavu-fonts-common-2.33-6.el7.noarch                      14/31 
  Verifying  : libXcomposite-0.4.4-4.1.el7.x86_64                         15/31 
  Verifying  : libXtst-1.2.3-1.el7.x86_64                                 16/31 
  Verifying  : libxcb-1.13-1.el7.x86_64                                   17/31 
  Verifying  : lksctp-tools-1.0.17-2.el7.x86_64                           18/31 
  Verifying  : 1:java-1.8.0-openjdk-devel-1.8.0.191.b12-1.el7_6.x86_64    19/31 
  Verifying  : xorg-x11-fonts-Type1-7.5-9.el7.noarch                      20/31 
  Verifying  : libxslt-1.1.28-5.el7.x86_64                                21/31 
  Verifying  : libX11-1.6.5-2.el7.x86_64                                  22/31 
  Verifying  : 1:java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64          23/31 
  Verifying  : dejavu-sans-fonts-2.33-6.el7.noarch                        24/31 
  Verifying  : javapackages-tools-3.4.1-11.el7.noarch                     25/31 
  Verifying  : 1:java-1.8.0-openjdk-headless-1.8.0.191.b12-1.el7_6.x86_   26/31 
  Verifying  : libXau-1.0.8-2.1.el7.x86_64                                27/31 
  Verifying  : libSM-1.2.2-2.el7.x86_64                                   28/31 
  Verifying  : libX11-common-1.6.5-2.el7.noarch                           29/31 
  Verifying  : tzdata-java-2018g-1.el7.noarch                             30/31 
  Verifying  : libfontenc-1.1.3-3.el7.x86_64                              31/31 

Installed:
  java-1.8.0-openjdk.x86_64 1:1.8.0.191.b12-1.el7_6                             
  java-1.8.0-openjdk-devel.x86_64 1:1.8.0.191.b12-1.el7_6                       

Dependency Installed:
  copy-jdk-configs.noarch 0:3.3-10.el7_5                                        
  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-1.8.0-openjdk-headless.x86_64 1:1.8.0.191.b12-1.el7_6                    
  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.5-2.el7                                                   
  libX11-common.noarch 0:1.6.5-2.el7                                            
  libXau.x86_64 0:1.0.8-2.1.el7                                                 
  libXcomposite.x86_64 0:0.4.4-4.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-6.el7                                           
  libxcb.x86_64 0:1.13-1.el7                                                    
  libxslt.x86_64 0:1.1.28-5.el7                                                 
  lksctp-tools.x86_64 0:1.0.17-2.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:2018g-1.el7                                              
  xorg-x11-font-utils.x86_64 1:7.5-21.el7                                       
  xorg-x11-fonts-Type1.noarch 0:7.5-9.el7                                       

Complete!
[root@server-1 ~]#

インストールされている java のバージョンを確認します。

[root@server-1 ~]# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
[root@server-1 ~]# 

複数バージョンのJDKが同時にインストールされている場合、 どのバージョンを利用するか選択して切り替える必要があるため、どのバージョンを利用するかの切り替えを行います。今回、インストールされている JDK のバージョンは1つであるため、確認のみとなります。

[root@server-1 ~]# alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java)

Enter to keep the current selection[+], or type selection number: 
[root@server-1 ~]#