在线下载JDK
命令:wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm
下载读取条:
查看当前文件夹下是否有JDK安装包:
添加执行权限:
命令:chmod +x jdk-8u131-linux-x64.rpm
执行rpm进行安装
命令:rpm -ivh jdk-8u131-linux-x64.rpm
查看JDK是否安装成功
命令:java -version
查看JDK的安装路径,(一般默认的路径:/usr/java/jdk1.8.0_131)
配置JDK环境变量
1、编辑环境变量
export JAVA_HOME=/usr/java/jdk1.8.0_131
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:JAVAHOME/lib:" role="presentation" style=" display: inline; line-height: normal; word-spacing: normal; overflow-wrap: normal; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border-width: 0px; border-style: initial; border-color: initial; ">JAVAHOME/lib:JAVAHOME/lib:{JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=JAVAHOME/bin:" role="presentation" style=" display: inline; line-height: normal; word-spacing: normal; overflow-wrap: normal; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border-width: 0px; border-style: initial; border-color: initial; ">JAVAHOME/bin:JAVAHOME/bin:{JRE_HOME}/bin
export PATH=PATH:" role="presentation" style=" display: inline; line-height: normal; word-spacing: normal; overflow-wrap: normal; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border-width: 0px; border-style: initial; border-color: initial; ">PATH:PATH:{JAVA_PATH}
2、编辑 /etc/profile
命令:vim /etc/profile
3、进行环境配置
命令:i 进入编辑模式
把上面编辑好的粘贴
输入命令::wq!
强制保存并退出
让profile立即生效:
source /etc/profile
查看JDK安装情况
1、使用javac命令,不会出现command not found
2、命令:java -version
3、 echo $PATH查看自己刚刚设置的环境变量配置是否都正确
yum 安装jdk
1.查看是否已安装JDK,卸载
yum list installed |grep java
java-1.8.0-openjdk.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.121-0.b13.el7_3 @updates
javapackages-tools.noarch 3.4.1-11.el7 @base
python-javapackages.noarch 3.4.1-11.el7 @base
tzdata-java.noarch 2016j-1.el7 @updates
2卸载CentOS系统Java环境
[root@192 ~]# yum -y remove java-1.8.0-openjdk* *表时卸载所有openjdk相关文件输入 [root@192 ~]# yum -y remove tzdata-java.noarch 卸载tzdata-java
3列出java环境安装包
yum -y list java*
或 [root@192 ~]# yum search java | grep -i --color JDK 查看JDK软件包列表
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel 安装JDK,如果没有java-1.8.0-openjdk-devel就没有javac命令