JDK環境部署
html
做者:尹正傑java
版權聲明:原創做品,謝絕轉載!不然將追究法律責任。node
一.JDK版本說明linux
1>.Open JDK 這個很少說,免費的開源實現,以 GPL License 發佈,不少 Linux 發行版中都會包含這個 Open JDK 。參與開發的大佬們有 Oracle、RedHat (已被 IBM 收購)、Azul System、IBM、Apple、SAP。 2>.Oracle JDK 就是咱們常說的 Java JDK,也是最經常使用的一個,是 Oracle 公司(收購了開發 Java 的 Sun 公司)對 Java SE 的實現。若是更詳細分的話,能夠分爲 Oracle JDK 和 Oracle JRE。好比你想玩 Minecraft 這樣須要 Java 的遊戲,那隻須要從 java.com 下載一個 JRE 就夠了。若是你想基於 Java 作開發,那就須要從 Oracle Technology Network(OTN)網站上下載 JDK 了。 假設 JDK 8u192 是 2018 年的最後一個 Update,你下載而且安裝了,那能夠繼續無償使用下去,沒有任何問題。可是從 2019 年 1 月開始,若是你還想獲取 JDK 的 Update,對不起,你須要付費訂閱。這個訂閱服務的價格是這樣的:對於 PC,每用戶每個月是 2.5 美圓,對於服務器/雲部署,每一個 processor 每個月是 25 美圓,固然,數量多的話能夠打折。 3>.其餘公司提供的 JDK 有實力的大公司,都有可能開發本身的 JDK ,好比 IBM ,確定要爲自家的操做系統 AIX,還有 z/OS 開發 SDK。HP、SAP 也有本身的 JDK,能夠爲本身的硬件和軟件作定製。 Oracle Java SE Advanced、Java SE Advanced Desktop、Java SE Suite 這名字很長,也有點費解,簡單來講,這是個收費的服務, 是 Oracle 爲企業級用戶提供的高級工具和功能,能夠監控、部署、管理企業級的 Java 程序,與此同時,你還能夠下載那些老版本的 JDK 及其 Update。換句話說,若是你購買了這個服務,天然就不用擔憂什麼 JDK Update 收費的問題。可是問題在於,到底有多少公司再使用這個服務? 若是你的公司在使用,歡迎告知。因此我猜想 Oracle 耍了一點小手段, 之後不要這個收費的服務了,把這些高級的功能加上 JDK Update 打包,統一成一個新的服務,就是以前說的訂閱服務。 注意,我這裏說的都是公司,都是商業用途,若是隻是我的學習 Java 的話,沒什麼影響! 以上文章參自互聯網:https://baijiahao.baidu.com/s?id=1620513576396123558&wfr=spider&for=pc
二.Open JDK的安裝部署web
1>.在CentOS7.6圖形界面安裝時,默認會給我們安裝該服務 bash
[root@node101.yinzhengjie.org.cn ~]# which java /usr/bin/java [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ll /usr/bin/java lrwxrwxrwx. 1 root root 22 Mar 11 13:57 /usr/bin/java -> /etc/alternatives/java [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ll /etc/alternatives/java lrwxrwxrwx. 1 root root 74 Mar 11 13:57 /etc/alternatives/java -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64/jre/bin/java [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# rpm -qa *openjdk* java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.5.el7.x86_64 java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64 java-11-openjdk-headless-11.0.ea.28-7.el7.x86_64 java-11-openjdk-11.0.ea.28-7.el7.x86_64 [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# java -version java version "1.7.0_191" OpenJDK Runtime Environment (rhel-2.6.15.5.el7-x86_64 u191-b01) OpenJDK 64-Bit Server VM (build 24.191-b01, mixed mode) [root@node101.yinzhengjie.org.cn ~]#
2>. CentOs的yum源默認就有openjdk的rpm包服務器
[root@node101.yinzhengjie.org.cn ~]# yum search jdk Loaded plugins: fastestmirror, langpacks Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com ===================================================================================================================== N/S matched: jdk ===================================================================================================================== copy-jdk-configs.noarch : JDKs configuration files copier java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without audio and video support java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment 8 java-1.8.0-openjdk-accessibility.i686 : OpenJDK accessibility connector java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector java-1.8.0-openjdk-accessibility-debug.i686 : OpenJDK accessibility connector for packages with debug on java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK 8 accessibility connector for packages with debug on java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment 8 with full debug on java-1.8.0-openjdk-demo.i686 : OpenJDK Demos java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos 8 java-1.8.0-openjdk-demo-debug.i686 : OpenJDK Demos with full debug on java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos 8 with full debug on java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment 8 java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full debug on java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment 8 with full debug on java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment java-1.8.0-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 8 java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full debug on java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full debug on java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK 8 API documentation for packages with debug on java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed in single archive java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK 8 API documentation compressed in single archive for packages with debug on java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle 8 java-1.8.0-openjdk-src-debug.i686 : OpenJDK Source Bundle for packages with debug on java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle 8 for packages with debug on java-11-openjdk.i686 : OpenJDK Runtime Environment 11 java-11-openjdk.x86_64 : OpenJDK Runtime Environment 11 java-11-openjdk-debug.i686 : OpenJDK Runtime Environment 11 with full debug on java-11-openjdk-debug.x86_64 : OpenJDK Runtime Environment 11 with full debug on java-11-openjdk-demo.i686 : OpenJDK Demos 11 java-11-openjdk-demo.x86_64 : OpenJDK Demos 11 java-11-openjdk-demo-debug.i686 : OpenJDK Demos 11 with full debug on java-11-openjdk-demo-debug.x86_64 : OpenJDK Demos 11 with full debug on java-11-openjdk-devel.i686 : OpenJDK Development Environment 11 java-11-openjdk-devel.x86_64 : OpenJDK Development Environment 11 java-11-openjdk-devel-debug.i686 : OpenJDK Development Environment 11 with full debug on java-11-openjdk-devel-debug.x86_64 : OpenJDK Development Environment 11 with full debug on java-11-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 11 java-11-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 11 java-11-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full debug on java-11-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full debug on java-11-openjdk-javadoc.i686 : OpenJDK 11 API documentation java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation java-11-openjdk-javadoc-debug.i686 : OpenJDK 11 API documentation for packages with debug on java-11-openjdk-javadoc-debug.x86_64 : OpenJDK 11 API documentation for packages with debug on java-11-openjdk-javadoc-zip.i686 : OpenJDK 11 API documentation compressed in single archive java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in single archive java-11-openjdk-javadoc-zip-debug.i686 : OpenJDK 11 API documentation compressed in single archive for packages with debug on java-11-openjdk-javadoc-zip-debug.x86_64 : OpenJDK 11 API documentation compressed in single archive for packages with debug on java-11-openjdk-jmods.i686 : JMods for OpenJDK 11 java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11 java-11-openjdk-jmods-debug.i686 : JMods for OpenJDK 11 with full debug on java-11-openjdk-jmods-debug.x86_64 : JMods for OpenJDK 11 with full debug on java-11-openjdk-src.i686 : OpenJDK Source Bundle 11 java-11-openjdk-src.x86_64 : OpenJDK Source Bundle 11 java-11-openjdk-src-debug.i686 : OpenJDK Source Bundle for packages with debug on java-11-openjdk-src-debug.x86_64 : OpenJDK Source Bundle 11 for packages with debug on ldapjdk-javadoc.noarch : Javadoc for ldapjdk icedtea-web.x86_64 : Additional Java components for OpenJDK - Java browser plug-in and Web Start implementation ldapjdk.noarch : The Mozilla LDAP Java SDK Name and summary matches only, use "search all" for everything. [root@node101.yinzhengjie.org.cn ~]#
3>.安裝OpenJDK1.8oracle
[root@node101.yinzhengjie.org.cn ~]# yum -y install java-1.8.0-openjdk-devel Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.201.b09-2.el7_6 will be installed --> Processing Dependency: java-1.8.0-openjdk(x86-64) = 1:1.8.0.201.b09-2.el7_6 for package: 1:java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64 --> Running transaction check ---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.201.b09-2.el7_6 will be installed --> Processing Dependency: java-1.8.0-openjdk-headless(x86-64) = 1:1.8.0.201.b09-2.el7_6 for package: 1:java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64 --> Running transaction check ---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.201.b09-2.el7_6 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================================================================================================== Package Arch Version Repository Size ========================================================================================================================================================================================================================================== Installing: java-1.8.0-openjdk-devel x86_64 1:1.8.0.201.b09-2.el7_6 updates 9.8 M Installing for dependencies: java-1.8.0-openjdk x86_64 1:1.8.0.201.b09-2.el7_6 updates 260 k java-1.8.0-openjdk-headless x86_64 1:1.8.0.201.b09-2.el7_6 updates 32 M Transaction Summary ========================================================================================================================================================================================================================================== Install 1 Package (+2 Dependent packages) Total download size: 42 M Installed size: 144 M Downloading packages: (1/3): java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64.rpm | 260 kB 00:00:00 (2/3): java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64.rpm | 9.8 MB 00:00:11 (3/3): java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64.rpm | 32 MB 00:00:18 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 2.3 MB/s | 42 MB 00:00:18 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64 1/3 Installing : 1:java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64 2/3 Installing : 1:java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64 3/3 Verifying : 1:java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64 1/3 Verifying : 1:java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64 2/3 Verifying : 1:java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64 3/3 Installed: java-1.8.0-openjdk-devel.x86_64 1:1.8.0.201.b09-2.el7_6 Dependency Installed: java-1.8.0-openjdk.x86_64 1:1.8.0.201.b09-2.el7_6 java-1.8.0-openjdk-headless.x86_64 1:1.8.0.201.b09-2.el7_6 Complete! [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# java -version #安裝後,他默認就會把新新安裝的版本連接過去。 openjdk version "1.8.0_201" OpenJDK Runtime Environment (build 1.8.0_201-b09) OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode) [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# which java /usr/bin/java [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ll /usr/bin/java lrwxrwxrwx. 1 root root 22 Apr 20 18:15 /usr/bin/java -> /etc/alternatives/java [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ll /etc/alternatives/java #看這裏,咱們發現他把連接只想了openjdk1.8啦! lrwxrwxrwx. 1 root root 73 Apr 20 18:15 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64/jre/bin/java [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# rpm -qa *openjdk* #查看已經存在的JDK版本 java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.5.el7.x86_64 java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64 java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64 java-11-openjdk-headless-11.0.ea.28-7.el7.x86_64 java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64 java-11-openjdk-11.0.ea.28-7.el7.x86_64 java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64 [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]#
三.Oracle JDK安裝部署(咱們演示基於tar包的方式安裝,咱們使用軟件是須要對軟件配置咱們jdk自定義安裝對路徑喲!若是基於rpm方式安裝通常狀況下並不須要!)less
1>.打開Oracle官方網站下載相應的平臺的安裝包(https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)jvm
2>.卸載平臺中已經存在的JDK版本
[root@node101.yinzhengjie.org.cn ~]# java -version openjdk version "1.8.0_201" OpenJDK Runtime Environment (build 1.8.0_201-b09) OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode) [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# rpm -qa *openjdk* java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.5.el7.x86_64 java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64 java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64 java-11-openjdk-headless-11.0.ea.28-7.el7.x86_64 java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64 java-11-openjdk-11.0.ea.28-7.el7.x86_64 java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64 [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.5.el7.x86_64 #卸載JDK版本! [root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64 [root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.201.b09-2.el7_6.x86_64 [root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-11-openjdk-headless-11.0.ea.28-7.el7.x86_64 [root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.8.0-openjdk-devel-1.8.0.201.b09-2.el7_6.x86_64 [root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-11-openjdk-11.0.ea.28-7.el7.x86_64 [root@node101.yinzhengjie.org.cn ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64 [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# rpm -qa *openjdk* [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# java -version -bash: /usr/bin/java: No such file or directory [root@node101.yinzhengjie.org.cn ~]#
3>.將下載的jdk版本進行解壓安裝並配置環境變量(若是你下載的是rpm包的oracle jdk的話就無需配置環境變量啦!)
[root@node101.yinzhengjie.org.cn ~]# mkdir /yinzhengjie/softwares -p [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# tar -zxf jdk-8u201-linux-x64.tar.gz -C /yinzhengjie/softwares/ [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/jdk1.8.0_201/ total 383856 drwxr-xr-x. 2 10 143 4096 Dec 16 03:45 bin -r--r--r--. 1 10 143 3244 Dec 16 03:45 COPYRIGHT -rw-r--r--. 1 root root 366447449 Apr 9 15:27 hadoop-2.9.2.tar.gz drwxr-xr-x. 3 10 143 4096 Dec 16 03:45 include -rw-r--r--. 1 10 143 5207434 Dec 12 17:07 javafx-src.zip drwxr-xr-x. 5 10 143 4096 Dec 16 03:45 jre drwxr-xr-x. 5 10 143 4096 Dec 16 03:45 lib -r--r--r--. 1 10 143 40 Dec 16 03:45 LICENSE drwxr-xr-x. 4 10 143 4096 Dec 16 03:45 man -r--r--r--. 1 10 143 159 Dec 16 03:45 README.html -rw-r--r--. 1 10 143 424 Dec 16 03:45 release -rw-r--r--. 1 10 143 21103945 Dec 16 03:45 src.zip -rw-r--r--. 1 10 143 108109 Dec 12 17:07 THIRDPARTYLICENSEREADME-JAVAFX.txt -r--r--r--. 1 10 143 155002 Dec 16 03:45 THIRDPARTYLICENSEREADME.txt [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# tail -3 /etc/profile #Add by yinzhengjie JAVA_HOME=/yinzhengjie/softwares/jdk1.8.0_201 PATH=$PATH:$JAVA_HOME/bin [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# source /etc/profile [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# java -version java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode) [root@node101.yinzhengjie.org.cn ~]#