CentOS7安装JDK8

  1. 检查是否已装有其他版本的JDK,执行命令:rpm -qa | grep java,得到结果如下:
[root@elk-server work]# rpm -qa | grep java
tzdata-java-2017c-1.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.151-2.6.11.1.el7_4.x86_64
java-1.7.0-openjdk-1.7.0.151-2.6.11.1.el7_4.x86_64
java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64
java-1.8.0-openjdk-headless-1.8.0.151-1.b12.el7_4.x86_64
python-javapackages-3.4.1-11.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch

如上所示,当前已有openjdk的1.7和1.8版本,我们需要将其卸载;
2. 卸载上一步发现的已装的jdk,执行以下命令:

rpm -e --nodeps \
java-1.7.0-openjdk-headless-1.7.0.151-2.6.11.1.el7_4.x86_64 \
java-1.7.0-openjdk-1.7.0.151-2.6.11.1.el7_4.x86_64 \
java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64 \
java-1.8.0-openjdk-headless-1.8.0.151-1.b12.el7_4.x86_64

3.下载jdk-8u161-linux-x64.tar.gz,官网地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
4. 解压:tar -zxvf jdk-8u161-linux-x64.tar.gz
5. 将解压后的文件夹移动到/usr/local目录下:mv jdk1.8.0_161 /usr/local/
6. 打开文件/etc/profile,添加以下内容:

export JAVA_HOME=/usr/local/jdk1.8.0_161
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib/dt.JAVA_HOME/lib/tools.jar:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${PATH}

7. 使配置立即生效: source /etc/profile 8. 查看当前java版本信息: java -version,可以看到如下基本内容: ```shell [root@elk-server ~]# java -version java version "1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode) ```

至此,CentOS7安装JDK8成功;

欢迎关注我的公众号:程序员欣宸

CentOS7安装JDK8_第1张图片

你可能感兴趣的:(java服务端)