卸载系统自带的
<div style="background-color: inherit;">
    rpm&nbsp;-aq|grep&nbsp;jdk|xargs&nbsp;rpm&nbsp;-e&nbsp;--nodeps
</div>


rpm -aq|grep java

rpm -e java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64 –nodeps

安装java

上传jdk-8u45-linux-x64.tar.gz

mkdir /usr/java/

tar -zxvf jdk-8u45-linux-x64.tar.gz -C /usr/java/

 

# vi /etc/profile 

添加以下:

JAVA_HOME=/usr/java/jdk1.8.0_45

JRE_HOME=/usr/java/jdk1.8.0_45/jre

PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

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

export JAVA_HOME JRE_HOME PATH CLASSPATH

 

或者

cat >>/etc/profile<<EOF

 


JAVA_HOME=/usr/java/jdk1.8.0_45
<div style="font: 14px/21px 微软雅黑; text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">
    JRE_HOME=/usr/java/jdk1.8.0_45/jre
</div>

<div style="font: 14px/21px 微软雅黑; text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">
    PATH=\$PATH:\$JAVA_HOME/bin:\$JRE_HOME/bin
</div>

<div style="font: 14px/21px 微软雅黑; text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">
    CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar:\$JRE_HOME/lib
</div>

<div style="font: 14px/21px 微软雅黑; text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">
    export&nbsp;JAVA_HOME&nbsp;JRE_HOME&nbsp;PATH&nbsp;CLASSPATH
</div>


 

EOF

 

最后:

source /etc/profile 

查看

 java -version