Setting Up Oracle Java on Ubuntu/Linux: A Comprehensive Guide

Setting Up Oracle Java on Ubuntu/Linux: A Comprehensive Guide

Determining System Architecture

To begin setting up Oracle Java on your Ubuntu/Linux system, the first step involves determining your system’s architecture. Execute the following command in your terminal:

file /sbin/init

This command will reveal whether your system is 32-bit or 64-bit, which is crucial for downloading the appropriate Oracle Java binaries.

Checking for Existing Java Installation

Before proceeding, it’s essential to verify if Java is already installed on your system. Execute the following command:

java -version

Ensure that the installed Java version is Oracle Java, not OpenJDK, for compatibility with this guide.

Removing OpenJDK/JRE and Preparing Directory

To avoid conflicts between different Java versions, it’s necessary to remove OpenJDK/JRE and create a directory for Oracle Java binaries. Execute the following commands:

sudo apt-get purge openjdk-*
sudo mkdir -p /usr/local/java

Downloading Oracle Java

Visit the Oracle website and download the appropriate Oracle Java JDK/JRE binaries for your system architecture (32-bit or 64-bit).

Copying Oracle Java Binaries

After downloading, copy the Oracle Java binaries to the designated directory. For 64-bit systems:

cd ~/Downloads
sudo cp -r jdk-7u45-linux-x64.tar.gz /usr/local/java
cd /usr/local/java

Extracting Java Binaries

Unpack the downloaded Java binaries using the following commands:

sudo tar xvzf jdk-7u45-linux-x64.tar.gz

Editing System Profile

Edit the system profile to include Oracle Java in the system PATH:

sudo nano /etc/profile

Add the following lines at the end of the file:

export JAVA_HOME=/usr/local/java/jdk1.7.0_45
export PATH=$PATH:$JAVA_HOME/bin

Informing System of Java Location

Notify the system about the Oracle Java location:

sudo update-alternatives –install “/usr/bin/java” “java” “/usr/local/java/jdk1.7.0_45/jre/bin/java” 1

Setting Oracle Java as Default

Set Oracle Java as the default Java runtime environment:

sudo update-alternatives –set java /usr/local/java/jdk1.7.0_45/jre/bin/java

Reloading System-wide PATH

Reload the system-wide PATH:

. /etc/profile

Testing Java Installation

Test the Java installation using:

java -version

Final Steps and Congratulations

Congratulations! You have successfully installed Oracle Java on your Ubuntu/Linux system. Reboot your system to finalize the configuration. Your system is now fully configured for running and developing Java programs. Enjoy exploring the possibilities!

Stractive offers a free of cost, no obligation migration readiness assessment to do TCO & ROI analysis, gauge health of the current setup and recommend future roadmap. For more information reach out to sales@stractive.com.