- 查看是否已安裝jdk
[root@izwz972rwz9s5l70pvt1djz ~]# java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
- 如果有則進(jìn)行卸載
[root@izwz972rwz9s5l70pvt1djz ~]# yum remove *java*
- 在http://www.oracle.com/technetwork/java/javase/downloads/上下載相應(yīng)版本的rpm包,執(zhí)行下面的命令安裝
[root@izwz972rwz9s5l70pvt1djz ~]# rpm -ivh jdk-8u161-linux-x64.rpm
- 測試是否安裝完成
[root@izwz972rwz9s5l70pvt1djz ~]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
[root@izwz972rwz9s5l70pvt1djz ~]# javac -version
javac 1.8.0_161
- 如果測試失敗則配置環(huán)境變量后在測試脐帝,默認(rèn)安裝路徑為/user/java包蓝,配置環(huán)境變量
[root@izwz972rwz9s5l70pvt1djz ~]# vim /etc/profile
在/etc/profile文件的最下面添加
export JAVA_HOME=/usr/java/jdk1.8.0_161
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
執(zhí)行source /etc/profile
使修改生效。