美文网首页
安装Java

安装Java

作者: 真织寒子 | 来源:发表于2018-01-23 22:14 被阅读0次

    1. 下载最新的JAVA JDK

    百度Java进入Oracle官网下载

    2. 解压缩文件并移动至/opt

    tar -xzvf jdk-8u162-linux-x64.tar.gz

    mv jdk1.8.0_162 /opt

    cd /opt/jdk1.8.0_162

    3. 设置环境变量

    1)执行 gedit ~/.bashrc , 并添加下列内容

    # install JAVA JDK

    export JAVA_HOME=/opt/jdk1.8.0_162

    export CLASSPATH=.:${JAVA_HOME}/lib

    export PATH=${JAVA_HOME}/bin:$PATH

    2)执行 source ~/.bashrc

    4. 安装并注册

    执行(分别对应java、javac和浏览器插件的安装与注册):

    update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_162/bin/java 1

    update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_162/bin/javac 1

    update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.7.0_162/jre/lib/amd64/libnpjp2.so 1

    update-alternatives --set java /opt/jdk1.8.0_91/bin/java

    update-alternatives --set javac /opt/jdk1.8.0_91/bin/javac

    update-alternatives --set mozilla-javaplugin.so /opt/jdk1.7.0_45/jre/lib/amd64/libnpjp2.so

    查看结果:

    update-alternatives --config java

    update-alternatives --config javac

    5. 测试

    java -version

    #output
    java version "1.8.0_162"
    Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

    相关文章

      网友评论

          本文标题:安装Java

          本文链接:https://www.haomeiwen.com/subject/wpveaxtx.html