CentOS 6.5 jdk-8u162-linux-x64.tar.gz
可通过查看java版本判断当前是否安装了jdk
# java -version # java -version java version "1.7.0_99" OpenJDK Runtime Environment (rhel-2.6.5.1.el6-x86_64 u99-b00) OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
查看安装的jdk包
# rpm -qa |grep jdk java-1.6.0-openjdk-1.6.0.38-1.13.10.4.el6.x86_64 java-1.7.0-openjdk-1.7.0.99-2.6.5.1.el6.x86_64
可通过 rpm -e --nodeps java-x.x.x-... 卸载已经安装的jdk。
# rpm -e --nodeps java-1.6.0-openjdk-1.6.0.38-1.13.10.4.el6.x86_64 # rpm -e --nodeps java-1.7.0-openjdk-1.7.0.99-2.6.5.1.el6.x86_64 # rpm -qa |grep jdk #
解压jdk-8u162-linux-x64.tar.gz
# tar -zxvf jdk-8u162-linux-x64.tar.gz
复制或剪切解压后文件到需要的位置 (/usr/local/jdk/)
mv jdk1.8.0_162/ /usr/local/jdk/配置环境变量,编辑 /etc/profile 末尾增加
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_162
export PATH=$JAVA_HOME/bin:$PATH
保存退出,使配置生效:
# source /etc/profile
验证
# java -version java version "1.8.0_162" Java(TM) SE Runtime Environment (build 1.8.0_162-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)