CentOS7.0默认自带OpenJDK,在安装Sun公司的JDK时,要先卸载自带的JDK,不然系统会不知道到底用哪个JDK而导致错误。
首先可以通过java -version查看系统自带的JDK:
java version "1.7.0"
OpenJDK Runtime Environment (build 1.7.0-b09)
OpenJDK 64-Bit Server VM (build 1.7.0-b09, mixed mode)
通过 rpm -qa | grep java查看JDK相关的包,
然后通过命令删除下面三个相关的包:
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.75-2.5.4.2.el7_0.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.75-2.5.4.2.el7_0.x86_64
rpm -e --nodeps tzdata-java-2015a-1.el7.noarch
然后到Sun官网下载JDK安装包,http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html
通过下面的命令安装Sun JDK(默认安装在/usr/java目录下):
rpm -ivh jdk-8u77-linux-x64.rpm
然后在/etc/profile 文件末尾添加java环境变量:
vim /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_77
export CLASSPATH=.:$HADOOP_HOME/sbin:$HADOOP_HOME/bin:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=.:$PATH:$JAVA_HOME/bin
执行下面命令使修改生效:
source /etc/profile
然后通过java -version查看:
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b01)
Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode, sharing)
reference:
http://blog.csdn.net/remote_roamer/article/details/49391821
http://blog.csdn.net/czmchen/article/details/41047187
http://www.linuxidc.com/Linux/2015-03/114787.htm
http://www.cnblogs.com/sixiweb/archive/2012/11/25/2787684.html