您的位置:首页 > 运维架构 > Linux

Linux CentOS 6.9安装 jdk-9.0.4_linux-x64

2018-01-24 21:35 330 查看
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位的JDK,64位的就下64位的JDK。Linux x86是32位JDK,Linux x64是64位JDK。

Linux下的JDK安装包现有两种格式.rpm和.tar.gz。rpm是redhat红帽的标准安装包,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

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)

 

查找名字包含java,jdk的已安装程序。查找到了,已经安装JDK,否则没有安装。命令行:

[plain] view
plain copy

rpm -qa | grep java  

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

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

rpm -qa | grep jdk | xargs rpm -e --nodeps  

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

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

[plain] view
plain copy

rpm -qa | grep java | xargs rpm -e --nodeps  

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

 

卸载后,查看JDK版本,已无信息,卸载成功。命令行:

[plain] view
plain copy

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

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

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生成java、javac等JDK的快捷方式图标,这些图标会链接指向到/usr/java/jdk-9.0.4_linux-x64中。用echo $PATH查看环境变量,可以看到/usr/bin是加入了PATH环境变量中的。命令行:

[plain] view
plain copy

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

java -version  

测试下javac命令是否可用。命令行:

[plain] view
plain copy

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

vi test.java  

[plain] view
plain copy

class test  

{  

   public static void main(String[]args)  

   {  

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

   }  

}  

[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

javac test.java  

[plain] view
plain copy

java test  

[root@localhost Desktop]# javac test.java

[root@localhost Desktop]# java test

Hello World!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: