安装jdk:

sudo chmod 777 /opt
cp jdk-8u101-linux-x64.tar.gz /opt
cd /opt
tar -xvf jdk-8u101-linux-x64.tar.gz
ls
/opt/jdk1.8.0_101/bin/java -version

配置java环境变量

JAVA_HOME:指定java的安装路径(/opt/jdk1.8.0_101)
PATH:指定可执行程序搜索路径

(PATH=$ JAVA_HOME/bin:$PATH)

CLASSPATH:指定java类装载路径(.)

cp ~/.bashrc ~/.bahsrc.bak
gedit ~/.bashrc

文件最后添加如下:

JAVA_HOME=/opt/jdk1.8.0_101
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.
export JAVA_HOME PATH CLASSPATH

重启bash

source ~/.bashrc
java -version