CentOS7安装JDK1.8

  1. 解压jdk -zxvf jdk-8u121-linux-x64.tar.gz
  2. 查看已安装的jdk
    [zyf@localhost soft]$ java -version
    openjdk version “1.8.0_102”
    OpenJDK Runtime Environment (build 1.8.0_102-b14)
    OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
    [zyf@localhost soft]$ rpm -qa | grep java
    java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
    javapackages-tools-3.4.1-11.el7.noarch
    java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
    java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
    tzdata-java-2016g-2.el7.noarch
    python-javapackages-3.4.1-11.el7.noarch
    java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
  3. 卸载OpenJDK
    [zyf@localhost soft]$ rpm -e –nodepsjava-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
    错误:can’t create 事务 lock on /var/lib/rpm/.rpm.lock (权限不够)
    [zyf@localhost soft]$ su
    密码:
    提示权限不足,登陆root用户继续卸载
    [root@localhost soft]# rpm -e –nodepsjava-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
    [root@localhost soft]# rpm -e –nodepsjava-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
    [root@localhost soft]# rpm -e –nodepsjava-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
    [root@localhost soft]# rpm -e –nodepstzdata-java-2016g-2.el7.noarch
  4. 安装JDK,只需要将最初解压的目录放到想要安装的位置即可
    配置环境变量
    [root@localhost soft]# vim /etc/profile
    在文件最后添加如下配置
    /#jdk环境变量
    JAVA_HOME=/home/zyf/work/soft/jdk1.8.0_121
    JRE_HOME=/home/zyf/work/soft/jdk1.8.0_121/jre
    CLASSPATH=.: JAVAHOME/lib/dt.jar: JAVA_HOME/lib/tools.jar: JREHOME/libPATH= PATH: JAVAHOME/bin: JRE_HOME/bin
    export JAVA_HOME JRE_HOME PATH CLASSPATH
    使修改立即生效
    [root@localhost soft]# source /etc/profile
    查看系统环境状态
    [root@localhost soft]# echo $PATH
    /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/zyf/.local/bin:/home/zyf/bin:/home/zyf/work/soft/jdk1.8.0_121/bin:/home/zyf/work/soft/jdk1.8.0_121/jre/bin
  5. 安装完成,可以通过java命令查看安装是否成功
    java
    javac
    java-version

转载地址: centos7安装jdk1.8

你可能感兴趣的:(Linux,CentOS7,jdk,java,openjdk)