1. 下载
打开官网,选择对应版本下载
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
我这里选择复制下载链接,到Linux执行wget命令下载
wget http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz?AuthParam=1530583574_d8faee97d8100908926d4e654b5917b8
下载完成如下
--2018-07-03 10:04:44-- http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz?AuthParam=1530583574_d8faee97d8100908926d4e654b5917b8
Resolving download.oracle.com (download.oracle.com)... 23.35.194.209
Connecting to download.oracle.com (download.oracle.com)|23.35.194.209|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 190890122 (182M) [application/x-gzip]
Saving to: ‘jdk-8u171-linux-x64.tar.gz?AuthParam=1530583574_d8faee97d8100908926d4e654b5917b8’
jdk-8u171-linux-x64.tar.gz?AuthParam=1530 100%[=====================================================================================>] 182.05M 1.95MB/s in 1m 42s
2018-07-03 10:06:26 (1.78 MB/s) - ‘jdk-8u171-linux-x64.tar.gz?AuthParam=1530583574_d8faee97d8100908926d4e654b5917b8’ saved [190890122/190890122]
2. 安装
- 在usr目录下新建java目录,将压缩包复制过去并解压,操作如下
cd /usr
mkdir java
cp jdk-8u171-linux-x64.tar.gz /usr/java/
tar -zxvf jdk-8u171-linux-x64.tar.gz
解压完成后,Java目录中的内容如下
total 183M
-rw-r--r-- 1 root root 183M Jul 3 10:14 jdk-8u171-linux-x64.tar.gz
drwxr-xr-x 0 uucp 143 512 Mar 29 08:18 jdk1.8.0_171
安装完成后可以建立个链接,节省目录长度,当然也可以不用
ln -s /usr/java/jdk1.8.0_171/ /usr/java8
3. 配置环境变量
修改profile内容
vim /etc/profile
在profile文件最下方加入如下内容
JAVA_HOME=/usr/java8
CLASSPATH=$JAVA_HOME/lib
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
保存退出执行source命令
source /etc/profile
4. 测试安装结果
执行java -version命令,返回如下结果即为安装成功
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)