1.添加webupd8team Java PPA(Personal Package Archives) repository到系統裏;java
$ vim /etc/apt/sources.list.d/java-8-debian.listweb
deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty mainubuntu
2.在安裝以前導入GPG key到系統驗證包的合法性;vim
$ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886oracle
出現如下的錯誤提示:
Error:
Executing: /tmp/apt-key-gpghome.iKAAqs0hjL/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys EEA14886
gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
gpg: connecting dirmngr at '/tmp/apt-key-gpghome.iKAAqs0hjL/S.dirmngr' failed: No such file or directory
gpg: keyserver receive failed: No dirmngr.net
Tip:No dirmngr
提示沒有dirmngr,安裝dirmngr:server
$ apt-get install software-properties-common dirmngr索引
$ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886ip
3.apt-get update(更新索引文件);get
$ apt-get update
4.安裝java8;
$ apt-get install oracle-java8-installer
5.查看java版本,以及java, javac命令是否可用;
$ java -version
$ java
$ javac
6.將oracle-java8設置爲默認的java環境;
$ apt-get install oracle-java8-set-default