首先到官網下載jdk-8u66-linux-x64.tar.gz,html
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htmljava
經過終端在/usr/local目錄下新建java文件夾,命令行:linux
sudo mkdir /usr/local/java
而後將下載到壓縮包拷貝到java文件夾中,命令行:centos
進入jdk源碼包所在目錄oracle
cp jdk-8u66-linux-x64.tar.gz /usr/local/java
而後進入java目錄,命令行:ui
cd /usr/local/java
解壓壓縮包,命令行:spa
sudo tar zxvf jdk-8u66-linux-x64.tar.gz
而後能夠把壓縮包刪除,命令行:.net
sudo rm jdk-8u66-linux-x64.tar.gz
這裏採用全局設置方法,就是修改etc/profile,它是是全部用戶的共用的環境變量命令行
vi /etc/profile
打開以後在末尾添加unix
JAVA_HOME=/usr/local/java/jdk1.8.0_66 JRE_HOME=/usr/local/java/jdk1.8.0_66/jre CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib PATH=$JAVA_HOME/bin:$PATH export PATH JAVA_HOME CLASSPATH
使環境變量生效
source /etc/profile
看看本身的配置是否都正確
echo $JAVA_HOME echo $CLASSPATH echo $PATH
若是系統已經安裝了其餘版本的Java
update-alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_66/bin/java 300 update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0_66/bin/javac 300 update-alternatives --config java update-alternatives --config javac
在終端
java -version
看看是否安裝成功,成功則顯示以下
java version "1.8.0_66" Java(TM) SE Runtime Environment (build 1.8.0_66-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
http://www.centoscn.com/image-text/install/2014/0827/3585.html