Linux下安装JDK
一、卸载原有的jdk
1、检查一下系统中的jdk版本
[root@localhost software]# java -version
显示:
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
2、检测jdk安装包
[root@localhost software]# rpm -qa | grep java
显示:
java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
tzdata-java-2016g-2.el7.noarch
java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
3、卸载openjdk
[root@localhost software]# rpm -e --nodeps tzdata-java-2016g-2.el7.noarch
[root@localhost software]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
[root@localhost software]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
[root@localhost software]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
[root@localhost software]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
或者使用
[root@localhost jvm]# yum remove *openjdk*
之后再次输入rpm -qa | grep java 查看卸载情况:
[root@localhost software]# rpm -qa | grep java
二、下载JDK
方式一:使用wget下载(以jdk1.8为例)
链接如下(可复制其他版本的下载链接):
--no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
[root@localhost software]#wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
方式二:直接将下载好的压缩包上传至linux并进行解压
[root@localhost software]# tar -zxvf jdk-8u131-linux-x64.tar.gz
三、配置环境变量
1、编辑 /etc/profile
[root@localhost software]# vim /etc/profile
在最前面添加:
export JAVA_HOME=##此处写上你的jdk目录的全路径
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
2、执行profile文件
[root@localhost software]# source /etc/profile
这样可以使配置不用重启即可立即生效。
四、检查新安装的jdk
[root@localhost software]# java -version
显示:
java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b11, mixed mode)
结束。