一、如何查看jdk是open jdk还是oracle jdk
通过输入java -version命令查看java的版本号
[root@app-01 alternatives]#java -version
(1)如果open jdk,输入java -version显示的版本信息为:
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (rhel-1.39.1.9.7.el6-x86_64)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
1
2
3
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (rhel-1.39.1.9.7.el6-x86_64)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
(2)如果是oracle的jdk,输入java -version显示的版本信息为:
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
1
2
3
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
二、CentOS7卸载OpenJDK安装Oracle JDK具体操作
1.查看JDK安装版本
[root@localhost ~]#java -version
java version *1.7.0_51*
OpenJDK Runtime Environment ( rhel-2.4.5.5.el7-x86_64 u51-b31)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
1
2
3
java version *1.7.0_51*
OpenJDK Runtime Environment ( rhel-2.4.5.5.el7-x86_64 u51-b31)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
2.查找OpenJDK安装包
rpm -qa | grep openjdk
java-1.7.0-openjdk-headless-1.7.0.51-2.4.5.5.el7.x86_64
java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64
1
2
java-1.7.0-openjdk-headless-1.7.0.51-2.4.5.5.el7.x86_64
java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64
3.卸载OpenJDK安装包
[root@localhost ~]#yum -y remove java-1.7.0-openjdkheadless.x86_64
[root@localhost ~]#yum -y remove java-1.7.0-openjdk.x86_64
1
2
[root@localhost ~]#yum -y remove java-1.7.0-openjdkheadless.x86_64
[root@localhost ~]#yum -y remove java-1.7.0-openjdk.x86_64
4.下载JDK1.7安装包
我这里的安装包是:jdk-7u79-linux-x64.tar.gz并放到了opt目录下。注意替换成自己的授权链接。
wget -O jdk-7u79-linux-x64.gz http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz?AuthParam=1480483544_0062bdc09e770901e37faba50ea8841e
1
wget-Ojdk-7u79-linux-x64.gzhttp://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz?AuthParam=1480483544_0062bdc09e770901e37faba50ea8841e
5.安装JDK1.7
解压安装包jdk-7u79-linux-x64.tar.gz:tar -xzvf jdk-7u79-linux-x64.tar.gz
查看该目录:ls
6.配置环境变量
修改配置文件:vi /etc/profile
在文件末尾添加如下内容
JAVA_HOME=/opt/jdk1.7.0_79
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
1
2
3
4
5
6
JAVA_HOME=/opt/jdk1.7.0_79
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
exportJAVA_HOME
exportPATH
exportCLASSPATH
退出:ESC
保存::wq
使配置文件生效:source /etc/profile
7.查看安装结果
java
javac
java -version
如果您认为本教程质量不错,读后觉得收获很大,预期工资能蹭蹭蹭的往上涨,那么不妨小额赞助我一下,让我有动力继续写出高质量的教程。