Although running update is absolutely not necessary here but to get wget package and make sure the system repository cache is up to date, run it once. Along with the commands to install wget tool.
sudo apt update
sudo apt install wget
Visit the official website and download the Jave 8 for Linux.
You can also copy the link and download it using the command given below:
wget "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=245797_df5ad55fdd604472a86a45a217032c7d" -O java-8.tar.gz
sudo mkdir /usr/java
sudo tar -xf java-8.tar.gz -C /usr/java
Here is the syntax to do that:
echo 'export PATH="$PATH:/usr/java/jre1.8.0_321/bin"' >> ~/.bashrc
source ~/.bashrc
Check version:
java -version
In the future, if you want to delete or remove the installed Java 8 version of Oracle from your Ubuntu 20.04 or 22.04 Linux, then run the following command:
sudo rm -r /usr/java/jre1.8*
Remove the exported path variable: nano ~/.bashrc
Scroll down and delete the line: export PATH="$PATH:/usr/java/jre1.8.0_321/bin"
Save the file Ctrl+O, hit the Enter, and then Ctrl+X to exit.