Oracle JDK 下载地址: https://www.oracle.com/technetwork/java/javase/downloads/index.html
创建目录:
/opt/jdk
, 将下载的 JDK 解压到此目录.
leo@uLinux:~/Downloads$ tar zxf jdk-8u202-linux-x64.tar.gz
leo@uLinux:~/Downloads$ sudo mv jdk1.8.0_202 /opt/jdk/
- 配置 Java 环境变量
打开/etc/profile
, 增加下面几行:
export JAVA_HOME=/opt/jdk/jdk1.8.0_202
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
- 配置生效
leo@uLinux:~/Downloads$ sudo vim /etc/profile
leo@uLinux:~/Downloads$ source /etc/profile
- 配置为系统默认JDK
- 使用
update-alternatives --config
来配置已有的系统默认JDK. - 使用
update-alternatives --install <link> <name> <path> <priority>
设置配置的JDK为系统默认JDK
- 使用
leo@uLinux:~$ sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_202/bin/java 1024
update-alternatives: using /opt/jdk/jdk1.8.0_202/bin/java to provide /usr/bin/java (java) in auto mode
leo@uLinux:~$ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_202/bin/javac 1024
update-alternatives: using /opt/jdk/jdk1.8.0_202/bin/javac to provide /usr/bin/javac (javac) in auto mode
- JDK 配置完毕.