Introduction
We can install Java on Ubuntu with various methods. Here we will see few important methods.
Using Ubuntu Packages
Step 1 : Update the packages of Ubuntu.
sudo apt-get update or sudo apt update
Step 2 : Verify if java is installed on Ubuntu.
java --version
As Java is not installed on Ubuntu yet we will get the above out put in the console logs.
Step 3 : Install Java.
Use the mentioned commands from output console to install Java as per the requirement. We can install the default Jre or Open Jdk.
sudo apt install default-jre
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless
Step 4 : Verify the Java Installation again.
On successful installation we will get the above output displaying the Java version installation details.
Using Oracle’s Official
Step 1 : Visit the URL to download the packages
https://launchpad.net/~linuxuprising/+archive/ubuntu/java/+packages
Note : You will need to create oracle account to download the binaries. If you have account you will get login prompt else sign up. It is very easy process to sign up and create a oracle account.
Step 2 : Create a directory and move the downloaded binary file into it.
sudo mkdir /usr/local/java
sudo mv jre-8u251-linux-x64.tar.gz /usr/local/java
Step 3 : Browse to the java directory and unpack the tar.gz file.
cd /usr/local/java sudo tar zvxf jre-8u251-x64.tar.gz
After unpack the tar file folder will be created jre1.8.0_251
Step 4 : Install the JRE
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.8.0_251/bin/java" 1
Step 5 : Once executing the command check the Java version
java -version
Hope this information was helpful to you.
Feel free to comment if you face any issues or have any doubts.