Linux CentOS 6.9安裝 jdk-9.0.4_linux-x64

Linux CentOS 6.9安裝 jdk-9.0.4_linux-x64

目錄

1、下載JDK

2、卸載JDK

3、安裝JDK

3.rpm後綴格式JDK安裝方式

4、驗證安裝


1、下載JDK

根據操作系統的位數下載對應的JDK,操作系統是32位的就下32位的JDK64位的就下64位的JDKLinux x8632JDKLinux x6464JDK

Linux下的JDK安裝包現有兩種格式.rpm.tar.gzrpmredhat紅帽的標準安裝包,rpm安裝時會自動配置。

本安裝示例在CentOS 6.6系統下進行,其它類型Linux系統安裝方式相同,下載的JDK版本爲jdk-9.0.4_linux-x64_bin.rpm,對.rpm.tar.gz安裝方式分別說明,本處已下載兩種格式的文件。

jdk-9.0.4_linux-x64_bin.rpm

下載地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html

 

2、卸載JDK

查看系統是否已安裝JDK。一般的linux都默認使用了開源的openJDK。顯示JDK版本信息,已經安裝JDK,否則沒有安裝。命令行:

[plain] view plain copy
  1. java -version  

[root@localhost ~]# java -version
java version "1.7.0_131"
OpenJDK Runtime Environment (rhel-2.6.9.0.el6_8-x86_64 u131-b00)
OpenJDK 64-Bit Server VM (build 24.131-b00, mixed mode)

 

查找名字包含javajdk的已安裝程序。查找到了,已經安裝JDK,否則沒有安裝。命令行:

[plain] view plain copy
  1. rpm -qa | grep java  
  2. rpm -qa | grep jdk  

[root@localhost ~]# rpm -qa | grep java
tzdata-java-2016j-1.el6.noarch
java-1.7.0-openjdk-1.7.0.131-2.6.9.0.el6_8.x86_64
java-1.6.0-openjdk-1.6.0.41-1.13.13.1.el6_8.x86_64
[root@localhost ~]# rpm -qa | grep jdk
java-1.7.0-openjdk-1.7.0.131-2.6.9.0.el6_8.x86_64
java-1.6.0-openjdk-1.6.0.41-1.13.13.1.el6_8.x86_64

 

已安裝JDK,卸載系統上JDK

單個卸載程序,使用rpm -e xxx命令。命令行:

[plain] view plain copy
  1. rpm -e jdk-1.7.0_79-fcs.x86_64  

[root@localhost Desktop]# rpm -e java-1.7.0-openjdk-1.7.0.131-2.6.9.0.el6_8.x86_64

批量卸載所有名字包含jdk的已安裝程序。命令行:

[plain] view plain copy
  1. rpm -qa | grep jdk | xargs rpm -e --nodeps  

[root@localhost Desktop]# rpm -qa | grep jdk | xargs rpm -e --nodeps

批量卸載所有名字包含java的已安裝程序。命令行:

[plain] view plain copy
  1. rpm -qa | grep java | xargs rpm -e --nodeps  

[root@localhost Desktop]# rpm -qa | grep java | xargs rpm -e --nodeps

 

卸載後,查看JDK版本,已無信息,卸載成功。命令行:

[plain] view plain copy
  1. java -version  

[root@localhost ~]# java -version
-bash: /usr/bin/java: 沒有那個文件或目錄

 

3.rpm後綴格式JDK安裝方式

安裝jdk-9.0.4_linux-x64_bin.rpm

給安裝包添加權限。命令行:

[plain] view plain copy
  1. chmod 755 jdk-9.0.4_linux-x64_bin.rpm  

[root@localhost Desktop]# chmod 755 jdk-9.0.4_linux-x64_bin.rpm

 

使用rpm -ivh xxx命令安裝JDK。命令行:

[plain] view plain copy
  1. rpm -ivh jdk-9.0.4_linux-x64_bin.rpm 

[root@localhost Desktop]# rpm -ivh jdk-9.0.4_linux-x64_bin.rpm

Preparing...                ########################################### [100%]

   1:jdk                    ########################################### [100%]

Unpacking JAR files...

rt.jar...

jsse.jar...

charsets.jar...

tools.jar...

localedata.jar...

jfxrt.jar...

 

安裝.rpm格式後綴的JDK不需要配置java環境變量,會自動配置,會在/usr/bin生成javajavacJDK的快捷方式圖標,這些圖標會鏈接指向到/usr/java/jdk-9.0.4_linux-x64中。用echo $PATH查看環境變量,可以看到/usr/bin是加入了PATH環境變量中的。命令行:

[plain] view plain copy
  1. echo $PATH  

[root@localhost Desktop]# echo $PATH

/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin

4、驗證安裝

安裝完成後,查看JDK版本。命令行:

[plain] view plain copy
  1. java -version  


測試下javac命令是否可用。命令行:

[plain] view plain copy
  1. javac  

[root@localhost Desktop]# javac

Usage: javac <options> <source files>

where possible options include:

  -g                         Generate all debugging info

  -g:none                    Generate no debugging info

  -g:{lines,vars,source}     Generate only some debugging info

  -nowarn                    Generate no warnings

  -verbose                   Output messages about what the compiler is doing

  -deprecation               Output source locations where deprecated APIs are used

  -classpath <path>          Specify where to find user class files and annotation processors

  -cp <path>                 Specify where to find user class files and annotation processors

  -sourcepath <path>         Specify where to find input source files

  -bootclasspath <path>      Override location of bootstrap class files

  -extdirs <dirs>            Override location of installed extensions

  -endorseddirs <dirs>       Override location of endorsed standards path

  -proc:{none,only}          Control whether annotation processing and/or compilation is done.

  -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process

  -processorpath <path>      Specify where to find annotation processors

  -d <directory>             Specify where to place generated class files

  -s <directory>             Specify where to place generated source files

  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files

  -encoding <encoding>       Specify character encoding used by source files

  -source <release>          Provide source compatibility with specified release

  -target <release>          Generate class files for specific VM version

  -version                   Version information

  -help                      Print a synopsis of standard options

  -Akey[=value]              Options to pass to annotation processors

  -X                         Print a synopsis of nonstandard options

  -J<flag>                   Pass <flag> directly to the runtime system

  -Werror                    Terminate compilation if warnings occur

  @<filename>                Read options and filenames from file

 

 

還可以寫段代碼測試下。用VI編輯java代碼測試JDK是否能正常編譯。按Insert鍵進入編輯狀態。命令行:

[plain] view plain copy
  1. vi test.java  
[plain] view plain copy
  1. class test  
  2. {  
  3.    public static void main(String[]args)  
  4.    {  
  5.       System.out.println("Hello World!");  
  6.    }  
  7. }  

[root@localhost Desktop]# vi test.java

class test

{

   public static void main(String[]args)

   {

      System.out.println("Hello World!");

   }

}

 

寫好後,按Esc退出,按Shift加英文冒號shift + :  然後輸入wq,按Enter回車鍵確認。

編譯運行。命令行:

[plain] view plain copy
  1. javac test.java  
[plain] view plain copy
  1. java test  

[root@localhost Desktop]# javac test.java

[root@localhost Desktop]# java test

Hello World!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章