一、准备工作
卸载默认安装的OpenJDK
请使用su root提权后再用
1.查找需要卸载的OpenJDK
[root@localhost /]# rpm -qa | grep openjdk | grep -v grep
java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64
2.依次卸载
[root@localhost /]# yum remove java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
[root@localhost /]# yum remove java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64
[root@localhost /]# yum remove java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64
[root@localhost /]# yum remove java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64
3.下载jdk8地址如下:
http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz?AuthParam=1510637880_0808a2fb2f39f5665c9f729efd58b097
下载目录:/usr/software/java/
jdk-8u121-linux-x64.tar.gz
[root@localhost /]# tar -zxvf jdk-8u121-linux-x64.tar.gz
安装目录:/usr/software/java/jdk1.8.0_121
4.配置环境变量
vi /etc/profile
在/etc/profile文件尾部添加
export JAVA_HOME=/usr/software/java/jdk1.8.0_121/
export CLASSPATH=.:$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命令重新加载/etc/profile文件,使修改的内容在当前shell窗口中生效。5.测试是否安装成功
[root@localhost jdk1.8.0_121]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
OK!!!