信息来源链接:
http://www.linuxidc.com/Linux/2016-09/134941.htm
http://blog.csdn.net/testcs_dn/article/details/39026213
https://zhidao.baidu.com/question/265772073.html
http://www.jb51.net/LINUXjishu/150570.html
安装
# 从oracle官网下载你需要的版本JDK的rpm文件
# 通过rpm命令安装jdk
rpm -ivh jdk-8u121-linux-x64.rpm
[root@iZ28nvy56w8Z ~]# rpm -ivh jdk-8u121-linux-x64.rpm\?AuthParam\=1492323051_47a487993c898f2155bfccc2860571b2
Preparing... ########################################### [100%]
1:jdk1.8.0_121 ########################################### [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
问题解决
# 安装时无法安装有冲突
# 通过yum命令查询已安装信息
yum list installed
[root@iZ28nvy56w8Z ~]# yum list installed|grep jdk
jdk1.8.0_121.x86_64 2000:1.8.0_121-fcs installed
# 卸载之前安装信息
yum -y remove jdk1.8.0_121.i586
[root@iZ28nvy56w8Z ~]# yum -y remove jdk1.8.0_121.i586
Loaded plugins: security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package jdk1.8.0_121.i586 2000:1.8.0_121-fcs will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================
Removing:
jdk1.8.0_121 i586 2000:1.8.0_121-fcs installed 266 M
Transaction Summary
=====================================================================================================================================
Remove 1 Package(s)
Installed size: 266 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Erasing : 2000:jdk1.8.0_121-1.8.0_121-fcs.i586 1/1
Verifying : 2000:jdk1.8.0_121-1.8.0_121-fcs.i586 1/1
Removed:
jdk1.8.0_121.i586 2000:1.8.0_121-fcs
Complete!
配置环境变量
# 设置JDK目录软链接
ln -s jdk1.8.0_121 currentjdk
# 修改系统环境变量/etc/profile,加入以下信息
# Java environment
JAVA_HOME=/usr/java/currentjdk
JRE_HOME=/usr/java/currentjdk/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
# 通过source命令使修改生效
source /etc/profile
查看JDK安装信息
# 查看Java版本
java -version
[root@iZ28nvy56w8Z jre]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
# 查看javac版本
javac -version
[root@iZ28nvy56w8Z jre]# javac -version
javac 1.8.0_121