一、删除OpenJDK:
sudo apt-get purge openjdk*
二、添加PPA:
root@ubuntu:~# add-apt-repository ppa:webupd8team/java The program 'add-apt-repository' is currently not installed. You can install it by typing:apt install software-properties-common
以上提示是因为add-apt-repository命令不存在,安装即可:
apt install software-properties-common
然后在执行添加PPA的命令:
root@ubuntu:~# add-apt-repository ppa:webupd8team/java Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK7 / JDK8 / JDK9). There are no actual Java files in this PPA. More info (and Ubuntu installation instructions):- for Oracle Java 7: http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html- for Oracle Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html Debian installation instructions:- Oracle Java 7: http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html- Oracle Java 8: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html Oracle Java 9 (for both Ubuntu and Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html For JDK9, the PPA uses standard builds from: https://jdk9.java.net/download/ (and not the Jigsaw builds!). Important!!! For now, you should continue to use Java 8 because Oracle Java 9 is available as an early access release (it should be released in 2016)! You should only use Oracle Java 9 if you explicitly need it, because it may contain bugs and it might not include the latest security patches! Also, some Java options were removed in JDK9, so you may encounter issues with various Java apps. More information and installation instructions (Ubuntu / Linux Mint / Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html More info: https://launchpad.net/~webupd8team/+archive/ubuntu/javaPress [ENTER] to continue or ctrl-c to cancel adding it gpg: keyring `/tmp/tmp08u3_3hk/secring.gpg' createdgpg: keyring `/tmp/tmp08u3_3hk/pubring.gpg' createdgpg: requesting key EEA14886 from hkp server keyserver.ubuntu.comgpg: /tmp/tmp08u3_3hk/trustdb.gpg: trustdb createdgpg: key EEA14886: public key "Launchpad VLC" importedgpg: no ultimately trusted keys foundgpg: Total number processed: 1gpg: imported: 1 (RSA: 1)OK
三、更新源:
sudo apt-get update
四、安装JDK1.8:
sudo apt-get install oracle-java8-installer
修改数字为6、7后,将会安装java6 (or 7)。
五、设置默认的jdk(配置环境变量):
sudo apt-get install oracle-java8-set-default
同样,修改数字为6 or 7 以后,将设置默认的java版本为6 or 7
六、查看版本:
root@ubuntu:~# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
版本切换:
sudo update-java-alternatives -s java-8-oracle
sudo apt-get remove oracle-java8-installer