Cài đặt Java 8 64-bit trên Ubuntu 22.04 | 20.04 LTS

Run system update, and have wget

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

Download Oracle Java 8 for Linux

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

Extract Java 8 Tar file on Linux

sudo mkdir /usr/java
sudo tar -xf java-8.tar.gz -C /usr/java

Add the folder to your system PATH

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

Uninstall or Remove Java 8 from Ubuntu

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.