首先去oracle官网下载安装包
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
解压下载的安装(一般情况我默认/usr/local/下放安装程序,/usr/local/src下放安装包)
[[email protected] src]#tar -zxvf jdk-8u51-linux-x64.gz
[[email protected] src]# mv jdk1.8.0_51/ /usr/local/
设置环境变量
方法1:创建属于jdk自己的变量
[[email protected] jdk1.8.0_51]# vi /etc/profile.d/java.sh
JAVA_HOME=/usr/local/jdk1.8.0_51
JAVA_BIN=/usr/local/jdk1.8.0_51/bin
JRE_HOME=/usr/local/jdk1.8.0_51/jre
CLASSPATH=.
PATH=$PATH:/usr/local/jdk1.8.0_51/bin:/usr/local/jdk1.8.0_51/jre/bin
CLASSPATH=//usr/local/jdk1.8.0_51/jre/lib:/usr/local/jdk1.8.0_51/lib:/usr/local/jdk1.8.0_51/jre/lib/charsets.jar
[[email protected] jdk1.8.0_51]# . /etc/profile.d/java.sh
查看安装是否成功
[[email protected] jdk1.8.0_51]# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
方法2:在全局变量下面添加
[[email protected] jdk1.8.0_51]# vi /etc/profile
export JAVA_HOME=/use/java/usr/java/jdk1.8.0_51
export JRE_HOME=/usr/java/jdk1.8.0_51/jre
export CLASSPATH=.:$JAVA_HOME/bin:%JRE_HOME/lib:%CLASSPAT
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH