1. 安装前,最好先删除Linux自带的OpenJDK:
(1)运行java-version,会发现Linux自带的OpenJDK,运行rpm -qa | grep OpenJDK,找出自带的OpenJDK名称;
(2)运行rpm - nodeps -e OpenJDK名称,删除OpenJDK;
2. 下载jdk-8u20-linux-x64.rpm,运行rpm -ivh jdk-8u20-linux-x64.rpm安装;
wget http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-i586.tar.gz?AuthParam=1478569610_1ada043c27d0a57536d2e6d48b49a200(下载地址通过官网获得)
3. 运行vim ~/.bash_profile(不要修改~/profile,该文件为系统配置文件)
,在文件末尾输入以下几行:
export JAVA_HOME=/usr/java/jdk1.8.0_20
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
保存,退出;
4. 运行source /etc/profile,使~/.bash_profile文件生效,或者重启;
5. 运行java -version,返回结果如下:
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
说明JDK1.8已经安装成功!