一、使用系统源或安装包安装
# centos
yum list *openjdk* #查看jdk版本
yum install java-1.8.0-openjdk
yum install java-11-openjdk
rpm -ivh jdk-8u281-linux-x64.rpm #CentOS 通过 rpm 包安装 Oracle JDK
#Ubuntu
apt-cache madison openjdk-8-jdk #查看jdk版本
apt install openjdk-8-jdk
apt install openjdk-11-jdk
#配置 JAVA_HOME:JAVA_HOME 环境变量,它指向 jdk的安装目录,Eclipse/Tomcat 等软件就是通过搜索 JAVA_HOME 变量来找到并使用安装好的 jdk
vim /etc/profile
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH
source /etc/profile
echo $JAVA_HOME
/usr/java/latest
二、二进制包安装 OracleJDK
https://www.oracle.com/downloads/ # 所有软件下载入口
https://www.oracle.com/java/technologies/oracle-java-archive-downloads.html # 所有版本页面 https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html # 下载地址
mkdir /apps
cd /apps
tar xf jdk-8u251-linux-x64.tar.gz
ln -sv /apps/jdk1.8.0_251 /apps/jdk
vim /etc/profile
export JAVA_HOME=/apps/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/to ols.jar
source /etc/profile
java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
三、二进制包安装 OpenJDK
http://openjdk.java.net/ #官网
http://openjdk.java.net/projects/jdk6/ #openjdk 官方版本信息
目前的 OpenJDK 8 和 11 版本由于红帽维护:
https://www.redhat.com/en/about/press-releases/leadership-openjdk-8-and-openjd k-11-transitions-red-hat #红帽的维护信息
https://developers.redhat.com/products/openjdk/download #红帽下载地址
http://jdk.java.net/archive/
http://jdk.java.net/java-se-ri/11
mkdir /apps
cd /apps/
tar xvf openjdk-11+28_linux-x64_bin.tar.gz
ln -sv /apps/jdk-11 /apps/jdk
vim /etc/profile
export JAVA_HOME=/apps/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/to ols.jar
source /etc/profile
java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)