1、下载JDK
从官网下载jdk8
jdk-8u5-linux-x64.tar.gz
2、解压
$ tar -zxvf jdk-8u5-linux-x64.tar.gz
解压出来是一个jdk1.8.0_05文件夹
3、将文件夹移动到安装目录
$ sudo mv jdk1.8.0_05 /usr/local/
4、配置环境变量 ,更改/etc/profile文件
sudo gedit /etc/profile
在文件最后加上如下几行:
export JAVA_HOME=/usr/local/jdk1.8.0_05
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
5、更改默认配置选项 ,依次执行如下命令
sudo update-alternatives --install /usr/bin/java java /usr/local/jdk1.8.0_05/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/local/jdk1.8.0_05/bin/javac 300
i add next:
sudo update-alternatives --install /usr/bin/jar jar /usr/local/jdk1.8.0_05/bin/jar 300
sudo update-alternatives --install /usr/bin/javah javah /usr/local/jdk1.8.0_05/bin/javah 300
sudo update-alternatives --install /usr/bin/javap javap /usr/local/jdk1.8.0_05/bin/javap 300