Centos7 安装java 环境

一卸载JDK

Centos7一般都会带有自己的openjdk,我们一般都回用oracle的jdk,所以要卸载

步骤一:查询系统是否以安装jdk

#rpm -qa|grep java

或 #rpm -qa|grep jdk

或 #rpm -qa|grep gcj

image

步骤二:卸载已安装的jdk

#rpm -e --nodeps java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64

#rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64

#rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64

#rpm -e --nodeps java-1.7.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64

image

步骤三:验证一下是还有jdk

#rpm -qa|grep java

#java -version

没有内容证明已经卸载干净了

image

二安装JDK

1.打开url选择jdk1.8下载
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

我选择linux x64版本:
2,下载
wget http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz?AuthParam=1531155951_4e06a4d17c6c1dbfb8440352e19dd2ae

3,安装
mkdir /usr/local/java
tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local/java/
4,设置环境变量
vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_171
export JRE_HOME={JAVA_HOME}/lib:{JAVA_HOME}/bin:$PATH
//使环境变量生效
source /etc/profile
添加软链接
ln -s /usr/local/java/jdk1.8.0_171/bin/java /usr/bin/java
检查
java -version

你可能感兴趣的:(Centos7 安装java 环境)