1.安装
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk
sudo apt-get install openjdk-8-jdk
切换路径到/etc/alternatives
查看软连接ll java*
lrwxrwxrwx1 root root 46 6月 3 17:41 java ->/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java*
lrwxrwxrwx1 root root 56 6月 3 17:41 java.1.gz ->/usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
lrwxrwxrwx1 root root 43 6月 3 17:41 javac -> /usr/lib/jvm/java-7-openjdk-amd64/bin/javac*
lrwxrwxrwx1 root root 53 6月 3 17:41 javac.1.gz ->/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javac.1.gz
lrwxrwxrwx1 root root 45 6月 3 17:41 javadoc ->/usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc*
lrwxrwxrwx1 root root 55 6月 3 17:41 javadoc.1.gz ->/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javadoc.1.gz
lrwxrwxrwx1 root root 43 6月 3 17:41 javah ->/usr/lib/jvm/java-7-openjdk-amd64/bin/javah*
lrwxrwxrwx1 root root 53 6月 3 17:41 javah.1.gz -> /usr/lib/jvm/java-7-openjdk-amd64/man/man1/javah.1.gz
lrwxrwxrwx1 root root 43 6月 3 17:41 javap ->/usr/lib/jvm/java-7-openjdk-amd64/bin/javap*
lrwxrwxrwx 1 root root 536月 3 17:41 javap.1.gz ->/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javap.1.gz
sudo update-alternatives --remove java/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
sudo update-alternatives --remove java/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
3.添加软链
sudo update-alternatives --install /usr/bin/jdk jdk/usr/lib/jvm/java-7-openjdk-amd64 1700
sudo update-alternatives --install /usr/bin/jdk jdk/usr/lib/jvm/java-8-openjdk-amd64 1800
4.配置环境变量
打开 ~/.bashrc
alias jdk='sudoupdate-alternatives --config jdk'
exportJAVA_HOME=/usr/bin/jdk
exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
原文链接:https://www.f2er.com/ubuntu/352747.html