3 Ways to Install Oracle Java on Ubuntu Linux

Introduction
Java is a widely-used programming language, and installing it on your Ubuntu Linux system is essential for running a variety of software applications. Oracle Java provides numerous features, including better cross-platform compatibility and enhanced performance optimisation. In this article, we will explore three methods to install Oracle Java on Ubuntu Linux.
Method 1: Using the Official Oracle Java Installation Package
1.1 Download the latest Oracle Java version
Visit the [Oracle Java download page](https://www.oracle.com/java/technologies/javase-downloads.html) and choose the appropriate version for your system (e.g. Java SE 11 LTS). Accept the license agreement and download the tar.gz file.
1.2 Extract the downloaded file
Open a terminal window and navigate to the directory where you downloaded the tar.gz file. Then, extract it using the following command:
“`
tar -xf jdk-{version}_linux-x64_bin.tar.gz
“`
Replace `{version}` with the actual version number you downloaded.
1.3 Move extracted files and set up environment variables
Move the extracted folder to `/opt/` using:
“`
sudo mv jdk-{version} /opt/
“`
Set up environment variables by editing `~/.bashrc` or `/etc/bash.bashrc`:
“`
sudo nano ~/.bashrc
“`
Add these lines at the end of the file:
“`
export JAVA_HOME=/opt/jdk-{version}
export PATH=$PATH:$JAVA_HOME/bin
“`
Save and exit, then run `source ~/.bashrc` to apply changes.
1.4 Verify installation
Check if Oracle Java is installed correctly by executing:
“`
java –version
“`
Method 2: Installing via apt-get package manager (Debian-based systems)
2.1 Add PPA repository
Open a terminal window and run the following commands to add the PPA repository:
“`
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
“`
2.2 Install Oracle Java
To install the latest version of Oracle Java, run the following command:
“`
sudo apt-get install oracle-java{version}-installer
“`
Replace `{version}` with the desired version number.
2.3 Verify installation
Check if Oracle Java is installed correctly by executing:
“`
java –version
“`
Method 3: Using SDKMAN (Software Development Kit Manager)
3.1 Install SDKMAN
Open a terminal window and execute the following command to install SDKMAN:
“`
curl -s “https://get.sdkman.io” | bash
“`
Restart your terminal and run `source “$HOME/.sdkman/bin/sdkman-init.sh”` to apply changes.
3.2 Install Oracle Java using SDKMAN
List available Java versions with:
“`
sdk list java
“`
Install your desired version by running:
“`
sdk install java {version}
“`
Replace `{version}` with the actual version number you want.
3.3 Verify installation
Ensure Oracle Java is installed correctly by executing:
“`
java –version
“`
Conclusion
We have discussed three methods to install Oracle Java on Ubuntu Linux: using the official installation package, installing via apt-get package manager, and employing SDKMAN. Each method has its benefits, and you can choose the one that suits your needs best. Happy coding!
