安装好的centos会自带openjdk,用命令java -version查看,如果有就卸载


[root@localhost ~]# rpm -qa|grep jdk


java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.x86_64


java-1.7.0-openjdk-1.7.0.9-2.3.4.1.el6_3.x86_64


[root@localhost ~]# rpm -qa|grep gcj


java-1.4.2-gcj-compat-1.4.2.0-40jpp.115  


libgcj-4.1.2-48.el5  


[root@localhost ~]# yum -y remove java java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.x86_64


[root@localhost ~]# yum -y remove java java-1.7.0-openjdk-1.7.0.9-2.3.4.1.el6_3.x86_64


[root@localhost ~]# yum -y remove java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115  


[root@localhost ~]# yum -y remove libgcj-4.1.2-48.el5 




1. 下载jdk安装包


jdk-7u79-linux-x64.tar.gz 


官网的太慢,给个百度网盘下载地址:http://pan.baidu.com/share/link?shareid=2793927523&uk=1678158691&fid=117337971851932




2、解压及移动


# tar jdk-7u79-linux-x64.tar.gz


# mv hadoop-2.6.0 /opt/hadoop-2.6.0




3、设置java环境变量


以root用户登陆编辑/etc/profile,加入以下内容:


# vi /etc/profile


export JAVA_HOME=/opt/jdk1.7.0


export JRE_HOME=/opt/jdk1.7.0/jre


export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH


export PATH=$JAVA_HOME/bin: $PATH




#source /etc/profile   # 立即生效




4、 验证是否装成功


# java -version


java version "1.7.0_79"


Java(TM) SE Runtime Environment (build 1.7.0_79-b15)


Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)