下载:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
解压:
sudo tar -xvzf jdk-8u111-linux-x64.tar.gz -C /usr/lib/jvm/sudo tar -xvzf jdk-8u111-linux-x64.tar.gz -C /usr/lib/jvm/
环境配置:
sudo gedit /etc/profile
文末添加
#JDK配置
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_111
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH```
配置生效:
source /etc/profile
update-alternatives配置:
sudo update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 3000
sudo update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 3000
sudo update-alternatives --install /usr/bin/jar jar $JAVA_HOME/bin/jar 3000
sudo update-alternatives --install /usr/bin/javah javah $JAVA_HOME/bin/javah 3000
sudo update-alternatives --install /usr/bin/javap javap $JAVA_HOME/bin/javap 3000
多个JDK配置的切换:
使用Command:
update-alternatives
update-alternatives --config java
update-alternatives --config javac
update-alternatives --config jar
update-alternatives --config javah
update-alternatives --config javap