1安装jdk8
joe@joe-Aspire-Z3730:~$ sudo add-apt-repository ppa:webupd8team/javaYou are about to add the following PPA to your system: Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK7 / JDK8 / JDK9). There are no actual Java files in this PPA.Important -> Why Oracle Java 7 And 6 Installers No Longer Work: http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.htmlUbuntu 16.10 Yakkety Yak is no longer supported by Canonical (and thus, Launchpad and this PPA). The PPA supports Ubuntu 17.10, 17.04, 16.04, 14.04 and 12.04.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.htmlDebian 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.htmlOracle Java 9 (for both Ubuntu and Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.htmlOracle JDK 9 is now considered stable. There are currently only 64bit builds (no other builds are available for download: http://www.oracle.com/technetwork/java/javase/downloads/index.html ) More info: https://launchpad.net/~webupd8team/+archive/ubuntu/javaPress [ENTER] to continue or ctrl-c to cancel adding itgpg: keyring `/tmp/tmp88YJjN/secring.gpg' createdgpg: keyring `/tmp/tmp88YJjN/pubring.gpg' createdgpg: requesting key EEA14886 from hkp server keyserver.ubuntu.comgpg: /tmp/tmp88YJjN/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
2: joe@joe-Aspire-Z3730:~$ sudo apt-get update
3:sudo apt-get install oracle-java8-installer 出现错误,没办法,只好参考 "Ubuntu 安装 JDK8 的两种方式()"中所说方法进行安装。后来太晚没有这样安装,第二天早上还是按步骤3直接安装成功了。
4:
joe@joe-Aspire-Z3730:~$ java -versionjava version "1.8.0_161"Java(TM) SE Runtime Environment (build 1.8.0_161-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)这说明原来的open jdk被替换了。如果要编译android源代码则可以通过下面的步骤5将jdk换回原来的版本。
5:
joe@joe-Aspire-Z3730:~$ update-java-alternatives -ljava-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64java-1.7.0-openjdk-amd64 1051 /usr/lib/jvm/java-1.7.0-openjdk-amd64java-8-oracle 1081 /usr/lib/jvm/java-8-oraclejoe@joe-Aspire-Z3730:~$ echo $JAVA_HOME/usr/lib/jvm/java-7-openjdk-amd64/joe@joe-Aspire-Z3730:~$ update-java-alternatives -s java-1.7.0-openjdk-amd64update-java-alternatives: no root privilegesjoe@joe-Aspire-Z3730:~$ sudo update-java-alternatives -s java-1.7.0-openjdk-amd64joe@joe-Aspire-Z3730:~$ java -versionjava version "1.7.0_121"OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-1ubuntu0.12.04.3)OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)joe@joe-Aspire-Z3730:~$ sudo update-java-alternatives -s java-8-oraclejoe@joe-Aspire-Z3730:~$ java -versionjava version "1.8.0_161"Java(TM) SE Runtime Environment (build 1.8.0_161-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
6:下面的命令执行之后,感觉是不是也将JAVA_HOME环境变量改一改???(没试过,感觉最好也对应改一改)
joe@joe-Aspire-Z3730:~$ echo $JAVA_HOME/usr/lib/jvm/java-7-openjdk-amd64/joe@joe-Aspire-Z3730:~$ ls /usr/lib/jvmdefault-java java-1.7.0-openjdk-amd64 java-6-openjdk-commonjava-1.6.0-openjdk java-6-openjdk java-7-openjdk-amd64java-1.6.0-openjdk-amd64 java-6-openjdk-amd64 java-8-oracle
7:
joe@joe-Aspire-Z3730:~$ gedit .profileJAVA_HOME=/usr/lib/jvm/java-8-oracle/ PATH=$PATH:$HOME/bin:$JAVA_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tool.jar export JAVA_HOME export PATHexport CLASSPATH
8:关闭终端再重启一个终端
joe@joe-Aspire-Z3730:~$ echo $JAVA_HOME/usr/lib/jvm/java-7-openjdk-amd64/