官网下载安装包地址: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html
安装完解压缩到指定目录(以jdk-8u161-linux-x64.tar.gz为例)
1.创建目录
sudo mkdir /usr/local/java
2.解压到上面创建的目录
sudo tar -zxvf jdk-8u161-linux-x64.tar.gz -C /usr/local/java
3.修改环境变量
sudo vim /etc/profile
在文件末尾加上下面的代码
#设置jdk环境
export JAVA_HOME=/usr/local/java/jdk1.8.0_161 #目录要换成自己解压的jdk目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
4.使环境变量生效
source /etc/profile
5.最后,测试jdk是否安装成功
java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
tyson@tyson:~/Downloads$ sudo vim /etc/profile
tyson@tyson:~/Downloads$ source /etc/profile
tyson@tyson:~/Downloads$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
安装成功!