Type the command
sudo apt install openjdk-8-jdk
When it is installed, type the command to see if it is installed successfully
java -version
If this page is displayed, the installation is successful. The version is 1.8.0_222
To uninstall, run the following command
sudo apt remove openjdk*
This uninstalls the OpenJDK
Install the OracleJDK. For example, go to the official website to download the JDK and select Linuxtar.gz
Configure the environment variables here and enter the command
sudo vim /etc/profile
Add these at the end
JAVA_HOME=/usr/local/ Java /jdk1.8.0_221 # CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=.:${JAVA_HOME}/bin:$PATH
Then make the configuration take effect
source /etc/profile
Then check to see if it works
java -version