先到官網(wǎng)下載jdk刹碾,我下的是jdk1.8的播掷,下載頁面鏈接:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下載完成后解壓JDK的壓縮包猛蔽,然后設(shè)置環(huán)境變量
1.我是把解壓后的文件放在/usr/local目錄下
cd /usr/local
2.下載jdk,然后解壓
wget http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz
tar -zxvf jdk-8u121-linux-x64.tar.gz
3.設(shè)置環(huán)境變量
vim /etc/profile
在profile中添加如下內(nèi)容:
JAVA_HOME=/usr/local/jdk1.8.0_121
JRE_HOME=/usr/local/jdk1.8.0_121/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
加上后保存修改,并運(yùn)行使其生效
source /etc/profile
4.驗(yàn)證JDK有效性
在命令行直接輸入 java -version脚线,查看輸出屎媳,我的輸出如下:
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)