How to Install OpenJDK JAVA 8 in Ubuntu

一、搜索可用 JDK 包

OpenJDK packages are available under native apt repositories. You can simply use apt-cache search command to search available java version for your Ubuntu system.

apt-cache search openjdk

二、安装

Use the below command to install OpenJDK on your Debian based systems using the package manager from the default repository. The below commands will install Java Development Kit (JDK) and Java Runtime Environment (JRE) both on your system. You can install JRE package only to setup Runtime Environment only.

sudo apt-get install openjdk-8-jre openjdk-8-jdk

三、查看

After installation of Java uses below command to verify the installed version of Java on your system.

java -version

四、设置环 Java 境变量

Its the best practice to set Java environment variable after installing java. To setup JAVA_HOME add following line to /etc/environment file, Path may be differ with your system architecture.

echo "JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/" >> /etc/environment
source /etc/environment

环境变量设置

转自:https://tecadmin.net/install-openjdk-java-ubuntu/