1. 下载合适的JDK安装包
  2. 创建Java JDK安装位置

    1
    sudo mkdir /opt/java
  3. 解压安装包

    1
    sudo tar -zvx -f jdk*.tar.gz /opt/java/
  4. 打开用户环境变量配置文件

    1
    sudo gedit ~/.bashrc
  5. 编辑

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    set JAVA_HOME=/usr/java/jdk1.8.0_141
    export JAVA_HOME
    set JRE_HOME=$JAVA_HOME/jre
    export JRE_HOME
    set JAVA_BIN=$JAVA_HOME/bin
    export JAVA_BIN
    set JAVA_LIB=$JAVA_HOME/lib
    export JAVA_LIB

    set CLASSPATH=.:$JAVA_LIB/tools.jar:$JAVA_LIB/dt.jar
    export CLASSPATH
    set PATH=$JAVA_BIN:$JRE_HOME/bin:$PATH
    export PATH
  6. 安装和注册java,javac

    1
    2
    3
    4
    update-alternatives --install /usr/bin/java java /opt/java/jdk*/bin/java 1
    update-alternatives --install /usr/bin/javac javac /opt/java/jdk*/bin/javac 1
    update-alternatives --set java /opt/java/jdk*/bin/java
    update-alternatives --set javac /opt/java/jdk*/bin/javac

JDK安装和注册

  1. 选择java,javac
    1
    2
    update-alternatives --config java
    update-alternatives --config javac

设置系统JDK环境