在CentOS 7中安装与配置JDK8
Posted 薛定谔
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在CentOS 7中安装与配置JDK8相关的知识,希望对你有一定的参考价值。
1. 检查已经安装的jdk
rpm -qa | grep java
可能的结果如下:
java-1.7.0-openjdk-1.7.0.99-2.6.5.0.el7_2.x86_64 python-javapackages-3.4.1-11.el7.noarch java-1.8.0-openjdk-headless-1.8.0.77-0.b03.el7_2.x86_64 java-1.8.0-openjdk-1.8.0.77-0.b03.el7_2.x86_64 tzdata-java-2016c-1.el7.noarch javapackages-tools-3.4.1-11.el7.noarch java-1.7.0-openjdk-headless-1.7.0.99-2.6.5.0.el7_2.x86_64
2. 移除已经安装的open-jdk及依赖的程序
yum remove tzdata-java-2016c-1.el7.noarch
此时所有的open-jdk和其它对open-jdk有依赖的软件都会被移除
3.到oracle下载jdk8, 如我下载的是jdk-8u65-linux-x64.rpm
在对应目录下执行安装命令:
rpm -ivh jdk-8u65-linux-x64.rpm
程序默认安装到 /usr/java/jdk1.8.0_65
检查安装情况:
[[email protected] jdk]# java -version java version "1.8.0_65" Java(TM) SE Runtime Environment (build 1.8.0_65-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode) [[email protected] jdk]# javac -version javac 1.8.0_65
检查文件路径:
[[email protected] jdk]# whereis java java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /usr/share/man/man1/java.1 [[email protected] jdk]# ll /usr/bin/java lrwxrwxrwx 1 root root 22 Mar 28 11:52 /usr/bin/java -> /etc/alternatives/java [[email protected] jdk]# ll /etc/alternatives/java lrwxrwxrwx 1 root root 34 Mar 28 11:52 /etc/alternatives/java -> /usr/java/jdk1.8.0_65/jre/bin/java
添加环境变量文件:
[[email protected] jdk]# vi /etc/profile.d/jdk8.sh
添加以下内容
JAVA_HOME=/usr/java/jdk1.8.0_65 JRE_HOME=/usr/java/jdk1.8.0_65/jre CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export JAVA_HOME JRE_HOME CLASSPATH
使修改生效
source /etc/profile
检查是否生效
[[email protected] jdk]# env|grep java JRE_HOME=/usr/java/jdk1.8.0_65/jre JAVA_HOME=/usr/java/jdk1.8.0_65 CLASSPATH=.:/usr/java/jdk1.8.0_65/lib/dt.jar:/usr/java/jdk1.8.0_65/lib/tools.jar:/usr/java/jdk1.8.0_65/jre/lib
到此OK了.
以上是关于在CentOS 7中安装与配置JDK8的主要内容,如果未能解决你的问题,请参考以下文章