此贴作记录,方便自己以后查看,读者也可以参考一下。

    下载

anxpp@ubuntu:~$ wget http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz

    然后有如下提示:

--2016-03-13 21:41:49--  http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz
Resolving download.oracle.com (download.oracle.com)... 61.213.168.26, 61.213.168.33
Connecting to download.oracle.com (download.oracle.com)|61.213.168.26|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://101.44.1.11/files/3161000004BE65C8/download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz [following]
--2016-03-13 21:41:54--  http://101.44.1.11/files/3161000004BE65C8/download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-x64.tar.gz
Connecting to 101.44.1.11:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 181365687 (173M) [application/octet-stream]
Saving to: ‘jdk-8u77-linux-x64.tar.gz’
100%[======================================================================>] 181,365,687 3.20MB/s
2016-03-13 21:42:44 (3.46 MB/s) - ‘jdk-8u77-linux-x64.tar.gz’ saved [181365687/181365687]

    表示下载完成。

    解压

    新建一个目录:

anxpp@ubuntu:/$ sudo mkdir /opt/java

    接下来就解压,我们就解压到刚刚新建的目录下:

anxpp@ubuntu:~$ sudo tar -zxvf jdk-8u77-linux-x64.tar.gz -C /opt/java

    设置环境变量

    打开对应文件:

anxpp@ubuntu:~$ sudo gedit /etc/environment 

    此处若不熟悉vi,使用gedit编辑吧:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:${JAVA_HOME}/bin"
JAVA_HOME=/opt/java/jdk1.8.0_77
JRE_HOME=${JAVA_HOME}/jre
CLASSPATH=".:${JAVA_HOME}/lib:${JRE_HOME}/lib"

    修改bashrc文件:

anxpp@ubuntu:~$ sudo gedit ~/.bashrc

    文件最后面添加如下内容:

export JAVA_HOME=/opt/java/jdk1.8.0_77  
export JRE_HOME=${JAVA_HOME}/jre   
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib   
export PATH=${JAVA_HOME}/bin:$PATH 

    生效刚刚的配置:

anxpp@ubuntu:~$ source ~/.bashrc

    跟windows的一样,可输入java -version检查JDK是否正确安装:

  01

    如果出现以上信息,表示JDK安装并配置正确,可以使用了。