centos安装jdk

  1. 查看是否已安装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)
  1. 如果有则进行卸载
[root@izwz972rwz9s5l70pvt1djz ~]# yum remove *java*
  1. 在http://www.oracle.com/technetwork/java/javase/downloads/上下载相应版本的rpm包,执行下面的命令安装
[root@izwz972rwz9s5l70pvt1djz ~]# rpm -ivh jdk-8u161-linux-x64.rpm 
  1. 测试是否安装完成
[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
  1. 如果测试失败则配置环境变量后在测试,默认安装路径为/user/java,配置环境变量
[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

执行source /etc/profile 使修改生效。

你可能感兴趣的:(centos安装jdk)