Linux 配置 JDK

下载JDK包

下载地址

解压缩,放到指定目录

mkdir /usr/lib/jvm
sudo mv jdk-xxx.tar.gz /usr/lib/jvm
sudo tar -zxvf jdk-xxx.tar.gz

设置环境变量

# vim ~/.bashrc
# set oracle jdk environment ## 这里JAVA_HOME要注意目录要换成自己解压的jdk 目录
export JAVA_HOME=/usr/lib/jvm
export JRE_HOME=${JAVA_HOME}/jre  
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  
export PATH=${JAVA_HOME}/bin:$PATH

设置系统默认JDK版本

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/bin/java 300  
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/bin/javac 300  
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/bin/jar 300   
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/bin/javah 300   
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/bin/javap 300 

然后执行: sudo update-alternatives --config java

测试JDK

输入命令java -version
显示结果如下说明JDK安装配置成功

java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)