# centos安装 java
[root@bogon ~]# 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)
进一步查看JDK信息:
[root@bogon ~]# rpm -qa|grep java java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 tzdata-java-2016g-2.el7.noarch javapackages-tools-3.4.1-11.el7.noarch 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 java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64 python-javapackages-3.4.1-11.el7.noarch [root@bogon ~]#
卸载OpenJDK,执行以下操作:
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 rpm -e --nodeps tzdata-java-2016g-2.el7.noarch rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
> 下载jdk
wget --no-check-certificate --no-cookie --header "Cookie: oraclelicense=accept-securebackup-cookie;" http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm
>因为oracle现在要同意协议才能下载,直接使用wget加链接下载不到,所以要加上前面的那些代码.
## 使用rpm安装下载的包
rpm -ivh jdk-8u144-linux-x64.rpm
输出
[root@bogon ~]# wget --no-check-certificate --no-cookie --header "Cookie: oraclelicense=accept-securebackup-cookie;" http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm --2017-09-05 15:25:45-- http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm Resolving download.oracle.com (download.oracle.com)... 184.50.238.49, 184.50.238.48 Connecting to download.oracle.com (download.oracle.com)|184.50.238.49|:80... connected. HTTP request sent, awaiting response... 302 Moved Temporarily Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm [following] --2017-09-05 15:25:46-- https://edelivery.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm Resolving edelivery.oracle.com (edelivery.oracle.com)... 184.50.91.58, 2600:1417:e:289::2d3e, 2600:1417:e:282::2d3e Connecting to edelivery.oracle.com (edelivery.oracle.com)|184.50.91.58|:443... connected. HTTP request sent, awaiting response... 302 Moved Temporarily Location: http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm?AuthParam=1504596464_3396241443c18f4fee2b51825ffccb26 [following] --2017-09-05 15:25:46-- http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm?AuthParam=1504596464_3396241443c18f4fee2b51825ffccb26 Connecting to download.oracle.com (download.oracle.com)|184.50.238.49|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 169971490 (162M) [application/x-redhat-package-manager] Saving to: ‘jdk-8u144-linux-x64.rpm’ 100%[===================================================================================================>] 169,971,490 1.65MB/s in 1m 40s 2017-09-05 15:27:26 (1.63 MB/s) - ‘jdk-8u144-linux-x64.rpm’ saved [169971490/169971490] [root@bogon ~]# rpm -ivh jdk-8u144-linux-x64.rpm Preparing... ################################# [100%] Updating / installing... 1:jdk1.8.0_144-2000:1.8.0_144-fcs ################################# [100%] Unpacking JAR files... tools.jar... plugin.jar... javaws.jar... deploy.jar... rt.jar... jsse.jar... charsets.jar... localedata.jar... [root@bogon ~]# java -version java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode) [root@bogon ~]#
# 配置环境变量
lrwxrwxrwx. 1 root root 16 Sep 5 15:28 default -> /usr/java/latest drwxr-xr-x. 9 root root 268 Sep 5 15:28 jdk1.8.0_144 lrwxrwxrwx. 1 root root 22 Sep 5 15:28 latest -> /usr/java/jdk1.8.0_144 [root@bogon java]# pwd /usr/java
>向 /etc/profile文件末尾追加以下内容
[root@bogon java]# sudo vim /etc/profile JAVA_HOME=/usr/java/latest JRE_HOME=/usr/java/latest/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@bogon java]# source /etc/profile //使修改立即生效 [root@bogon java]# echo $PATH //查看PATH值 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/latest/bin:/usr/java/latest/jre/bin [root@bogon java]#