安装JDK
1、yum方式安装JDK
1.1、配置yum仓库
gzip /etc/yum.repos.d/* curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo yum clean all yum makecache
1.2、安装jdk
yum install java -y
# 版本:java-1.8.0-openjdk
2、二进制方式安装
2.1、下载jdk
https://www.oracle.com/cn/java/technologies/downloads/ # 自行注册帐号下载 这里使用jdk-8u152-linux-x64.tar.gz
2.2、安装jdk
tar xf jdk-8u152-linux-x64.tar.gz -C /usr/local/ ln -s /usr/local/jdk1.8.0_152 /usr/local/jdk cat >>/etc/profile<<'EOF' export JAVA_HOME=/usr/local/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar EOF source /etc/profile
2.3、验证是否安装成功
2.3.1、查询版本
]# java -version java version "1.8.0_152" Java(TM) SE Runtime Environment (build 1.8.0_152-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
2.3.2、检查javac
]# javac Usage: javac <options> <source files> where possible options include: -g Generate all debugging info -g:none Generate no debugging info -g:{lines,vars,source} Generate only some debugging info ...