下载java包 (这里以java8为例)
java包的下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
解压java包
$ mv jdk-8u131-linux-x64.tar.gz /opt
$ tar zxvf jdk-8u131-linux-x64.tar.gz
配置java环境
$ sudo nano /etc/profile
在末尾添加
-----------------------------------------------------------------------------------------------------
#java
export JAVA_HOME=/opt/jdk1.8.0_131
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
-----------------------------------------------------------------------------------------------------
然后保存
$ source /etc/profile
查看java版本号
$ java -version