1. 下载rpm
http://www.oracle.com/technetwork/java/javase/downloads/index.html
2. 查看原有jdk
[root@localhost ~]# java -version
[root@localhost ~]# rpm -qa | grep java
3. 卸载(全新安装跳过此步骤)
[root@localhost ~]# rpm -e --nodeps ....
4. 安装新的jdk
[root@localhost ~]# rpm -ivh jdk-8u141-linux-x64.rpm
# 或者
# centos下
[root@localhost ~]# yum localinstall jdk-8u141-linux-x64.rpm
JDK默认安装在/usr/java中
5. 验证安装
执行以下操作,查看信息是否正常:
[root@localhost ~]# java
[root@localhost ~]# javac
[root@localhost ~]# java -version
java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)
6. 配置环境变量
vi /etc/profile
# 向文件里面追加以下内容:
JAVA_HOME=/usr/java/jdk1.8.0_141
JRE_HOME=/usr/java/jdk1.8.0_141/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
使修改生效.
# 使修改立即生效
[root@localhost ~]# source /etc/profile
# 查看PATH值
[root@localhost ~]# echo $PATH
查看系统环境状态
[root@localhost ~]# echo $PATH