How To Install Oracle Java on Ubuntu or Debian

Java is a programming technology originally developed by Sun Microsystems and later acquired by Oracle. Oracle Java is a proprietary implementation for Java that is free to download and use for commercial use, but not to redistribute, therefore it is not included in a officially maintained repository. In this tutorial, we will discuss about “How To Install Oracle Java on Ubuntu or Debian” systems.

Please note that following tutorial is applicable for FedoraUbuntu and (perhaps) Linux Mint. I have tried these steps on Ubuntu 14.04.

Before we go on seeing the process to install Java, let’s quickly understand the difference between JRE, OpenJDK and Oracle JDK.

  • JRE (Java Runtime Environment) is what you would need normally to run a Java based application. This is all you need if you are not a programmer.
  • Server JRE: Java Runtime Environment. For deploying Java applications on servers. Includes tools for JVM monitoring and tools commonly required for server applications.
  • JDK stands for Java Development Kit and this is what you need to if you have to do some development (read programming) related to Java.
  • OpenJDK is Open Source implementation of Java Development Kit while Oracle JDK is the official Oracle version of Java Development Kit. While OpenJDK is sufficient for most of the cases, some programs such Android Studio suggests to use Oracle JDK to avoid UI/performance issue.

There are many reasons why you would want to install Oracle Java over OpenJDK.

Procedure to Install Oracle Java on Ubuntu or Debian

Options –

  1. Manually Install Oracle Java on Ubuntu or Debian from Binary Packages hosted at Oracle Repositories.
  2. Automatically Install Oracle Java on Ubuntu or Debian using official package manager and VIA PPA REPOSITORY.

RECOMMANDED READ: How to Install Oracle Java on Ubuntu using PPA

Check if Java is already installed

Use one following commands:

# java -version
The program ‘java’ can be found in the following packages:
* default-jre
* gcj-4.6-jre-headless
* openjdk-6-jre-headless
* gcj-4.5-jre-headless
* openjdk-7-jre-headless
Try: sudo apt-get install

If you see an output like the one above, it means you don’t have Java installed.

How To Manually Install Oracle Java on Ubuntu or Debian

 Know whether you are running a 32 bit or a 64 bit OS

uname -m
  • x86_64: 64 bit kernel
  • i686: 32 bit kernel

Downloading Oracle Java JDK

Go to the Oracle Java SE (Standard Edition) website and click Download JDK. You can also directly go to Java SE Development Kit 8 Downloads.

In this tutorial we will be installing the JDK Java SE Development Kit 8 x64 bits. Accept the license and right click and save the right tar.gz (64 or 32 bits) for your platform.

Alternatively you can also copy the download link and use wget to download the archive, Here are the instructions –

# cd ~/Downloads
# wget --header "Cookie: oraclelicense=accept-securebackup-cookie" <FileLink>

Replace the File link with the link you copied above. It is recommended to Always get the latest version from Oracle’s website.

Installing Oracle JDK on Ubuntu or Debian

Get sudo privileges for your system and create directory /opt/jdk. After that you need to go to the directory where image was downloaded, “~/Downloads”.

# sudo su
# mkdir -p /opt/jdk/jdk180102
# cd ~/Downloads

Un-compress the downloaded file to the /opt/jdk directory, and verify the contents

# tar -zxf jdk-8u102-linux-x64.tar.gz -C /opt/jdk
# ls /opt/jdk/
jdk1.8.0_102
# ls /opt/jdk/jdk1.8.0_102/
bin db javafx-src.zip lib man release THIRDPARTYLICENSEREADME-JAVAFX.txt
COPYRIGHT include jre LICENSE README.html src.zip THIRDPARTYLICENSEREADME.txt

Setting Oracle JDK as the default JVM

Once you have installed the JDK in /opt directory, you need to update your system environment to use this JDK. In our case, the java executable is located under /opt/jdk/jdk1.8.0_102/bin/java . To set it as the default JVM in your machine run following command:

# update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_102/bin/java 2000
update-alternatives: using /opt/jdk/jdk1.8.0_102/bin/java to provide /usr/bin/java (java) in auto mode

# update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_102/bin/javac 2000
update-alternatives: using /opt/jdk/jdk1.8.0_102/bin/javac to provide /usr/bin/javac (javac) in auto mode

Now Verify your JDK installation

# update-alternatives --display java
java - auto mode
 link currently points to /opt/jdk/jdk1.8.0_102/bin/java
/opt/jdk/jdk1.8.0_102/bin/java - priority 2001

# update-alternatives --display javac
javac - auto mode
 link currently points to /opt/jdk/jdk1.8.0_102/bin/javac
/opt/jdk/jdk1.8.0_102/bin/javac - priority 2001
Current 'best' version is '/opt/jdk/jdk1.8.0_102/bin/javac'.

Another easy way to check your installation

# java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

(Optional) Updating Java

To update Java, simply download an updated version from Oracle’s website and extract it under the /opt/jdk directory, then set it up as the default JVM with a higher priority number (in this case 110):

# update-alternatives --install /usr/bin/java java /opt/jdk/jdk.new.version/bin/java 2002
# update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk.new.version/bin/javac 2002

You can keep the old version or delete it

# update-alternatives --remove java /opt/jdk/jdk.old.version/bin/java
# update-alternatives --remove javac /opt/jdk/jdk.old.version/bin/javac

# rm -rf /opt/jdk/jdk.old.version

So this concludes our tutorial on Manually Install Oracle Java on Ubuntu or Debian.

I have successfully tried the above installation procedure on Ubuntu 14.04 LTS distribution. Same can be applied to Debian distribution or Mint Linux Machine.

If you encounter any problem after following above steps, please feel free to post a comment below.

 

 

One thought on “How To Install Oracle Java on Ubuntu or Debian

Leave a Reply

Your email address will not be published. Required fields are marked *

mautic is open source marketing automation