2021年7月20日 星期二

[研究]Java安裝與版本切換 (CentOS 8.4 x64)

[研究]Java安裝與版本切換 (CentOS 8.4 x64)

2021-07-20

CentOS 8.4 提供的 Java 版本,不提供單純的 JRE,都是 JDK。


[john@localhost ~]$ yum list | grep java
HdrHistogram-javadoc.noarch                            2.1.11-3.module_el8.4.0+721+9e20c0c2              appstream        
abrt-java-connector.x86_64                             1.1.0-16.el8                                      appstream        
brlapi-java.x86_64                                     0.6.7-32.el8                                      appstream        
byteman-javadoc.noarch                                 4.0.4-2.el8                                       appstream        
directory-maven-plugin-javadoc.noarch                  0.3.1-2.module_el8.4.0+721+9e20c0c2               appstream        
google-noto-sans-javanese-fonts.noarch                 20161022-7.el8.1                                  appstream        
icedtea-web-javadoc.noarch                             1.8.4-4.el8                                       appstream        
jaf-javadoc.noarch                                     1.2.1-5.module_el8.4.0+721+9e20c0c2               appstream        
java-1.8.0-openjdk.x86_64                              1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-accessibility.x86_64                1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-demo.x86_64                         1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-devel.x86_64                        1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-headless.x86_64                     1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-headless-slowdebug.x86_64           1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-javadoc.noarch                      1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-javadoc-zip.noarch                  1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-slowdebug.x86_64                    1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-src.x86_64                          1:1.8.0.292.b10-1.el8_4                           appstream        
java-11-openjdk.x86_64                                 1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-demo.x86_64                            1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-devel.x86_64                           1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-headless.x86_64                        1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-javadoc.x86_64                         1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-javadoc-zip.x86_64                     1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-jmods.x86_64                           1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-src.x86_64                             1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-static-libs.x86_64                     1:11.0.11.0.9-2.el8_4                             appstream        
java-atk-wrapper.x86_64                                0.33.2-6.el8                                      appstream        
javapackages-filesystem.noarch                         5.3.0-1.module_el8.0.0+11+5b8c10bd                appstream        
javapackages-tools.noarch                              5.3.0-1.module_el8.0.0+11+5b8c10bd                appstream        
jmc-core-javadoc.noarch                                8.0.0-2.module_el8.4.0+721+9e20c0c2               appstream        
libguestfs-java.x86_64                                 1:1.40.2-27.module_el8.4.0+783+f8734d30           appstream        
libguestfs-java-devel.x86_64                           1:1.40.2-27.module_el8.4.0+783+f8734d30           appstream        
libguestfs-javadoc.noarch                              1:1.40.2-27.module_el8.4.0+783+f8734d30           appstream        
lz4-java.x86_64                                        1.7.1-14.module_el8.4.0+708+63f8a724              appstream        
lz4-java-javadoc.noarch                                1.7.1-14.module_el8.4.0+708+63f8a724              appstream        
mariadb-java-client.noarch                             2.2.5-3.el8                                       appstream        
owasp-java-encoder.noarch                              1.2.2-3.module_el8.4.0+721+9e20c0c2               appstream        
owasp-java-encoder-javadoc.noarch                      1.2.2-3.module_el8.4.0+721+9e20c0c2               appstream        
postgresql-jdbc-javadoc.noarch                         42.2.3-3.el8_2                                    appstream        
subversion-javahl.noarch                               1.10.2-4.module_el8.3.0+703+ba2f61b7              appstream        
systemtap-runtime-java.x86_64                          4.4-10.el8                                        appstream        
tzdata-java.noarch                                     2021a-1.el8                                       appstream        
[john@localhost ~]$

[john@localhost ~]$ yum list | grep jre

[john@localhost ~]$ yum list | grep jdk
copy-jdk-configs.noarch                                3.7-4.el8                                         appstream        
java-1.8.0-openjdk.x86_64                              1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-accessibility.x86_64                1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-demo.x86_64                         1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-devel.x86_64                        1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-headless.x86_64                     1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-headless-slowdebug.x86_64           1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-javadoc.noarch                      1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-javadoc-zip.noarch                  1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-slowdebug.x86_64                    1:1.8.0.292.b10-1.el8_4                           appstream        
java-1.8.0-openjdk-src.x86_64                          1:1.8.0.292.b10-1.el8_4                           appstream        
java-11-openjdk.x86_64                                 1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-demo.x86_64                            1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-devel.x86_64                           1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-headless.x86_64                        1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-javadoc.x86_64                         1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-javadoc-zip.x86_64                     1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-jmods.x86_64                           1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-src.x86_64                             1:11.0.11.0.9-2.el8_4                             appstream        
java-11-openjdk-static-libs.x86_64                     1:11.0.11.0.9-2.el8_4                             appstream        
[john@localhost ~]$ 

安裝Java,預設會安裝 Java 8 ( 1.8.0)


[john@localhost ~]$ yum -y install java
Error: This command has to be run with superuser privileges (under the root user on most systems).
[john@localhost ~]$ sudo yum -y install java
[sudo] password for john: 
Sorry, try again.
[sudo] password for john: 
Last metadata expiration check: -1 day, 17:46:58 ago on Tue 20 Jul 2021 03:48:03 AM EDT.
Dependencies resolved.
===============================================================================================================================================
 Package                                   Architecture         Version                                          Repository               Size
===============================================================================================================================================
Installing:
 java-1.8.0-openjdk                        x86_64               1:1.8.0.292.b10-1.el8_4                          appstream               335 k
Installing dependencies:
 copy-jdk-configs                          noarch               3.7-4.el8                                        appstream                27 k
 java-1.8.0-openjdk-headless               x86_64               1:1.8.0.292.b10-1.el8_4                          appstream                34 M
 javapackages-filesystem                   noarch               5.3.0-1.module_el8.0.0+11+5b8c10bd               appstream                30 k
 lksctp-tools                              x86_64               1.0.18-3.el8                                     baseos                  100 k
 ttmkfdir                                  x86_64               3.0.9-54.el8                                     appstream                62 k
 tzdata-java                               noarch               2021a-1.el8                                      appstream               192 k
 xorg-x11-fonts-Type1                      noarch               7.5-19.el8                                       appstream               522 k
Enabling module streams:
 javapackages-runtime                                           201801                                                                        

Transaction Summary
===============================================================================================================================================
Install  8 Packages

Total download size: 35 M
Installed size: 119 M
Downloading Packages:
(1/8): copy-jdk-configs-3.7-4.el8.noarch.rpm                                                                   435 kB/s |  27 kB     00:00    
(2/8): javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch.rpm                                   1.6 MB/s |  30 kB     00:00    
(3/8): ttmkfdir-3.0.9-54.el8.x86_64.rpm                                                                        1.9 MB/s |  62 kB     00:00    
(4/8): tzdata-java-2021a-1.el8.noarch.rpm                                                                      2.8 MB/s | 192 kB     00:00    
(5/8): java-1.8.0-openjdk-1.8.0.292.b10-1.el8_4.x86_64.rpm                                                     1.4 MB/s | 335 kB     00:00    
(6/8): xorg-x11-fonts-Type1-7.5-19.el8.noarch.rpm                                                              3.8 MB/s | 522 kB     00:00    
(7/8): lksctp-tools-1.0.18-3.el8.x86_64.rpm                                                                    309 kB/s | 100 kB     00:00    
(8/8): java-1.8.0-openjdk-headless-1.8.0.292.b10-1.el8_4.x86_64.rpm                                            3.2 MB/s |  34 MB     00:10    
-----------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                          2.2 MB/s |  35 MB     00:16     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Running scriptlet: copy-jdk-configs-3.7-4.el8.noarch                                                                                     1/1 
  Running scriptlet: java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.x86_64                                                            1/1 
  Preparing        :                                                                                                                       1/1 
  Installing       : lksctp-tools-1.0.18-3.el8.x86_64                                                                                      1/8 
  Running scriptlet: lksctp-tools-1.0.18-3.el8.x86_64                                                                                      1/8 
  Installing       : tzdata-java-2021a-1.el8.noarch                                                                                        2/8 
  Installing       : ttmkfdir-3.0.9-54.el8.x86_64                                                                                          3/8 
  Installing       : xorg-x11-fonts-Type1-7.5-19.el8.noarch                                                                                4/8 
  Running scriptlet: xorg-x11-fonts-Type1-7.5-19.el8.noarch                                                                                4/8 
  Installing       : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch                                                     5/8 
  Installing       : copy-jdk-configs-3.7-4.el8.noarch                                                                                     6/8 
  Installing       : java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.x86_64                                                            7/8 
  Running scriptlet: java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.x86_64                                                            7/8 
  Installing       : java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64                                                                     8/8 
  Running scriptlet: java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64                                                                     8/8 
  Running scriptlet: copy-jdk-configs-3.7-4.el8.noarch                                                                                     8/8 
  Running scriptlet: java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64                                                                     8/8 
  Verifying        : copy-jdk-configs-3.7-4.el8.noarch                                                                                     1/8 
  Verifying        : java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64                                                                     2/8 
  Verifying        : java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.x86_64                                                            3/8 
  Verifying        : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch                                                     4/8 
  Verifying        : ttmkfdir-3.0.9-54.el8.x86_64                                                                                          5/8 
  Verifying        : tzdata-java-2021a-1.el8.noarch                                                                                        6/8 
  Verifying        : xorg-x11-fonts-Type1-7.5-19.el8.noarch                                                                                7/8 
  Verifying        : lksctp-tools-1.0.18-3.el8.x86_64                                                                                      8/8 
Installed products updated.

Installed:
  copy-jdk-configs-3.7-4.el8.noarch                                  java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64                        
  java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.x86_64         javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch        
  lksctp-tools-1.0.18-3.el8.x86_64                                   ttmkfdir-3.0.9-54.el8.x86_64                                             
  tzdata-java-2021a-1.el8.noarch                                     xorg-x11-fonts-Type1-7.5-19.el8.noarch                                   

Complete!
[john@localhost ~]$ 

測試


[john@localhost ~]$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
[john@localhost ~]$ 

先安裝 Java 8,再安裝 Java 11 後,測試發先系統仍使用 Java 8

xxx
[john@localhost ~]$ sudo yum -y install java-11
Last metadata expiration check: 0:00:45 ago on Mon 19 Jul 2021 09:49:16 PM EDT.
Dependencies resolved.
================================================================================   
 Package                    Arch     Version                  Repository   Size
================================================================================
Installing:
 java-11-openjdk            x86_64   1:11.0.11.0.9-2.el8_4    appstream   260 k
Installing dependencies:
 java-11-openjdk-headless   x86_64   1:11.0.11.0.9-2.el8_4    appstream    39 M

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 40 M
Installed size: 171 M
Downloading Packages:
(1/2): java-11-openjdk-11.0.11.0.9-2.el8_4.x86_ 2.5 MB/s | 260 kB     00:00    
(2/2): java-11-openjdk-headless-11.0.11.0.9-2.e 2.2 MB/s |  39 MB     00:18    
--------------------------------------------------------------------------------
Total                                           2.1 MB/s |  40 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.11.0.9-2.el8_4.x86_6   1/1 
  Preparing        :                                                        1/1 
  Installing       : java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_6   1/2 
  Running scriptlet: java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_6   1/2 
  Installing       : java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64           2/2 
  Running scriptlet: java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64           2/2 
  Verifying        : java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64           1/2 
  Verifying        : java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_6   2/2 
Installed products updated.

Installed:
  java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64                                  
  java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_64                         

Complete!
[john@localhost ~]$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
[john@localhost ~]$ 


********************************************************************************

VM快照還原

先安裝  Java 11

xxx
[john@localhost ~]$ sudo yum install -y java-11-openjdk
CentOS Linux 8 - AppStream                      2.4 MB/s | 8.1 MB     00:03    
CentOS Linux 8 - BaseOS                         894 kB/s | 3.6 MB     00:04    
CentOS Linux 8 - Extras                          14 kB/s | 9.8 kB     00:00    
Last metadata expiration check: -1 day, 16:00:04 ago on Tue 20 Jul 2021 05:41:40 AM EDT.
Dependencies resolved.
================================================================================
 Package                  Arch   Version                        Repo       Size
================================================================================
Installing:
 java-11-openjdk          x86_64 1:11.0.11.0.9-2.el8_4          appstream 260 k
Installing dependencies:
 copy-jdk-configs         noarch 3.7-4.el8                      appstream  27 k
 java-11-openjdk-headless x86_64 1:11.0.11.0.9-2.el8_4          appstream  39 M
 javapackages-filesystem  noarch 5.3.0-1.module_el8.0.0+11+5b8c10bd
                                                                appstream  30 k
 lksctp-tools             x86_64 1.0.18-3.el8                   baseos    100 k
 ttmkfdir                 x86_64 3.0.9-54.el8                   appstream  62 k
 tzdata-java              noarch 2021a-1.el8                    appstream 192 k
 xorg-x11-fonts-Type1     noarch 7.5-19.el8                     appstream 522 k
Enabling module streams:
 javapackages-runtime            201801                                        

Transaction Summary
================================================================================
Install  8 Packages

Total download size: 41 M
Installed size: 173 M
Downloading Packages:
(1/8): copy-jdk-configs-3.7-4.el8.noarch.rpm    1.0 MB/s |  27 kB     00:00    
(2/8): javapackages-filesystem-5.3.0-1.module_e 2.3 MB/s |  30 kB     00:00    
(3/8): ttmkfdir-3.0.9-54.el8.x86_64.rpm         2.5 MB/s |  62 kB     00:00    
(4/8): java-11-openjdk-11.0.11.0.9-2.el8_4.x86_ 2.9 MB/s | 260 kB     00:00    
(5/8): xorg-x11-fonts-Type1-7.5-19.el8.noarch.r 4.7 MB/s | 522 kB     00:00    
(6/8): tzdata-java-2021a-1.el8.noarch.rpm       1.1 MB/s | 192 kB     00:00    
(7/8): lksctp-tools-1.0.18-3.el8.x86_64.rpm     389 kB/s | 100 kB     00:00    
(8/8): java-11-openjdk-headless-11.0.11.0.9-2.e 5.2 MB/s |  39 MB     00:07    
--------------------------------------------------------------------------------
Total                                           4.4 MB/s |  41 MB     00:09     
warning: /var/cache/dnf/appstream-a520ed22b0a8a736/packages/copy-jdk-configs-3.7-4.el8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS Linux 8 - AppStream                      1.6 MB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <security@centos.org>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Running scriptlet: copy-jdk-configs-3.7-4.el8.noarch                      1/1 
  Running scriptlet: java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_6   1/1 
  Preparing        :                                                        1/1 
  Installing       : lksctp-tools-1.0.18-3.el8.x86_64                       1/8 
  Running scriptlet: lksctp-tools-1.0.18-3.el8.x86_64                       1/8 
  Installing       : tzdata-java-2021a-1.el8.noarch                         2/8 
  Installing       : ttmkfdir-3.0.9-54.el8.x86_64                           3/8 
  Installing       : xorg-x11-fonts-Type1-7.5-19.el8.noarch                 4/8 
  Running scriptlet: xorg-x11-fonts-Type1-7.5-19.el8.noarch                 4/8 
  Installing       : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b   5/8 
  Installing       : copy-jdk-configs-3.7-4.el8.noarch                      6/8 
  Installing       : java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_6   7/8 
  Running scriptlet: java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_6   7/8 
  Installing       : java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64           8/8 
  Running scriptlet: java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64           8/8 
  Running scriptlet: copy-jdk-configs-3.7-4.el8.noarch                      8/8 
  Running scriptlet: java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64           8/8 
  Verifying        : copy-jdk-configs-3.7-4.el8.noarch                      1/8 
  Verifying        : java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64           2/8 
  Verifying        : java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_6   3/8 
  Verifying        : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b   4/8 
  Verifying        : ttmkfdir-3.0.9-54.el8.x86_64                           5/8 
  Verifying        : tzdata-java-2021a-1.el8.noarch                         6/8 
  Verifying        : xorg-x11-fonts-Type1-7.5-19.el8.noarch                 7/8 
  Verifying        : lksctp-tools-1.0.18-3.el8.x86_64                       8/8 
Installed products updated.

Installed:
  copy-jdk-configs-3.7-4.el8.noarch                                             
  java-11-openjdk-1:11.0.11.0.9-2.el8_4.x86_64                                  
  java-11-openjdk-headless-1:11.0.11.0.9-2.el8_4.x86_64                         
  javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch             
  lksctp-tools-1.0.18-3.el8.x86_64                                              
  ttmkfdir-3.0.9-54.el8.x86_64                                                  
  tzdata-java-2021a-1.el8.noarch                                                
  xorg-x11-fonts-Type1-7.5-19.el8.noarch                                        

Complete!
[john@localhost ~]$ 

測試

xxx
[john@localhost ~]$ java -version
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode, sharing)
[john@localhost ~]$ 

再安裝 Java 8

xxx
[john@localhost ~]$ sudo yum -y install java
Last metadata expiration check: -1 day, 16:01:41 ago on Tue 20 Jul 2021 05:41:40 AM EDT.
Dependencies resolved.
================================================================================
 Package                      Arch    Version                  Repository  Size
================================================================================
Installing:
 java-1.8.0-openjdk           x86_64  1:1.8.0.292.b10-1.el8_4  appstream  335 k
Installing dependencies:
 java-1.8.0-openjdk-headless  x86_64  1:1.8.0.292.b10-1.el8_4  appstream   34 M

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 34 M
Installed size: 118 M
Downloading Packages:
(1/2): java-1.8.0-openjdk-1.8.0.292.b10-1.el8_4 2.8 MB/s | 335 kB     00:00    
(2/2): java-1.8.0-openjdk-headless-1.8.0.292.b1 6.1 MB/s |  34 MB     00:05    
--------------------------------------------------------------------------------
Total                                           5.5 MB/s |  34 MB     00:06     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Running scriptlet: java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.   1/1 
  Preparing        :                                                        1/1 
  Installing       : java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.   1/2 
  Running scriptlet: java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.   1/2 
  Installing       : java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64      2/2 
  Running scriptlet: java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64      2/2 
  Verifying        : java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64      1/2 
  Verifying        : java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.   2/2 
Installed products updated.

Installed:
  java-1.8.0-openjdk-1:1.8.0.292.b10-1.el8_4.x86_64                             
  java-1.8.0-openjdk-headless-1:1.8.0.292.b10-1.el8_4.x86_64                    

Complete!
[john@localhost ~]$ 

測試,是 Java 8


[john@localhost ~]$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
[john@localhost ~]$ 

********************************************************************************

先安裝 Java 8,再安裝 Java 11 後,測試發先系統仍使用 Java 8。

先安裝 Java 11,再安裝 Java 8 後,測試發先系統改用新安裝的Java 8。

********************************************************************************

切換版本

強行指定系統使用的 Java 版本


[john@localhost ~]$ 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.11.0.9-2.el8_4.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el8_4.x86_64/jre/bin/java)

Enter to keep the current selection[+], or type selection number: 1
failed to create /var/lib/alternatives/java.new: Permission denied

[john@localhost ~]$ sudo 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.11.0.9-2.el8_4.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el8_4.x86_64/jre/bin/java)

Enter to keep the current selection[+], or type selection number: 1

[john@localhost ~]$ java -version
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode, sharing)
[john@localhost ~]$ 


(完)

沒有留言:

張貼留言