官网下载地址:
下载jdk并将其解压后放到/usr/local目录下:
tar -xvf jdk-8u92-linux-x64.tar.gz
cd jdk1.8.0_92
chmod 755 bin
验证是否安装成功:
[root@PCjdk1.8.0_92]# ./bin/java -version
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
mv /download/jdk1.8.0_92 /usr/local/
建立/usr/local/下的jdk软连接方便以后版本升级:
ln -s/usr/local/jdk1.8.0_92/ /usr/local/jdk
配置环境变量:
在/etc/profile中加入以下内容:
JAVA_HOME=/usr/local/jdk1.8.0_92
JAVA_BIN=/usr/local/jdk1.8.0_92/bin
PATH=$PATH:$JAVA_BIN
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
保存退出
[root@master~]source /etc/profile
查看java环境变量是否生效
[root@PClocal]# java -version
javaversion "1.8.0_92"
Java(TM)SE Runtime Environment (build 1.8.0_92-b14)
JavaHotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
测试成功