1 查看是否已经安装JDK
java -version
javac -version
2 在/usr/目录下创建java目录
[root@localhost ~]# mkdir/usr/java
[root@localhost ~]# cd /usr/java
3 下载jdk,然后解压
下载可以在http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 找到
wget http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
tar -zxvf jdk-8u144-linux-x64.tar.gz
4 设置环境变量
[root@localhost java]# vi /etc/profile
在profile中添加如下内容:
#set java environment
JAVA_HOME=/usr/java/jdk1.8.0_144JRE_HOME=/usr/java/jdk1.8.0_144/jreCLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/libPATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binexport JAVA_HOME JRE_HOME CLASS_PATH PATH让修改生效:
[root@localhost java]# source /etc/profile
5 y验证有效性
[root@host java]# java -version
java version "1.8.0_144"Java(TM) SE Runtime Environment (build 1.8.0_144-b01)Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)