Install Openjdk directly through commands in ubuntu. Here I choose the default version in the system package management.
Friendly reminder: the latest version of JDK is installed
Install Openjdk
sudo apt-get install default-jre default-jdk
Configure environment variables
vim ~/.bashrc
Add the following code to the end of the .bashrc file in the file. Press first to i
enter edit mode
export JAVA_HOME=/usr/lib/jvm/default-java
After inputting, press esc
+ :wq!
save to exit
and reload the configuration file
source ~/.bashrc
Verify that the installation is successful
java -version