How To Manually Install Oracle Java on a Debian or Ubuntu VPS

Introduction

A programming technology, Java, was developed originally by Sun Microsystems and was acquired by Oracle later. Oracle Java is Java’s proprietary implementation that can be downloaded freely and utilized for commercial purpose, but not to be redistributed, hence it doesn’t find inclusion in a repository that is maintained officially.

Multiple reasons are there for you wanting to install Oracle Java over OpenJDK. In this guide, the differences between these two will not be discussed.

Assumptions

This guide requires you to possess a VPS running Ubuntu 12.04 or Debian 7 or above. You need to have the root privileges (via sudo) for completing the tutorial.

You must know if you are operating a 64 bit or a 32 bit OS:

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

Downloading Oracle Java JDK

Use your web browser to visit the Oracle Java SE (Standard Edition) website and then decide the version that you want to deploy:

  • JDK: Java Development Kit. It includes comprehensive JRE plus tools to develop, debug, and monitor Java applications.
  • Server JRE: Java Runtime Environment. For installation of Java applications on servers. It includes tools for JVM monitoring and tools required generally for server applications.

In this guide, we will install the JDK Java SE Development Kit 8 x64 bits. You need to accept the license and copy the download link to your clipboard. Don’t forget to choose the right tar.gz (64 or 32 bits). Utilize wget for downloading the archive to your server:

  wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz

 

Oracle does not permit downloads unless their license is accepted, hence we need to change our request’s header. Alternately, utilize your browser to just download the compressed file and upload it manually by utilizing a SFTP/FTP client.

Always obtain the advanced version from Oracle’s website and change this tutorial’s commands as per the downloaded file.

Installing Oracle JDK

In this particular section, you will requiresudo privileges:

sudo su

The /opt directory has been reserved for all those add-on packages and software which are not part of the default deployment. A directory needs to be created for your JDK deployment:

 mkdir /opt/jdk

andjava needs to be extracted into the /opt/jdk directory:

tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk

It needs to be verified that the file is extracted into the /opt/jdk directory.

ls /opt/jdk

Setting Oracle JDK as the default JVM

In this case, the java executable can be found under /opt/jdk/jdk1.8.0_05/bin/java. For setting it as the default JVM in your machine, the command given below needs to run:

update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100

and

 update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100

Verify your installation

It can be verified that java is configured successfully by running the command below:

 update-alternatives --display java

and

update-alternatives --display javac

The output will look something like this:

java - auto mode
    link currently points to /opt/jdk/jdk1.8.0_05/bin/java
    /opt/jdk/jdk1.8.0_05/bin/java - priority 100
    Current 'best' version is '/opt/jdk/jdk1.8.0_05/bin/java'.

    javac - auto mode
    link currently points to /opt/jdk/jdk1.8.0_05/bin/javac
    /opt/jdk/jdk1.8.0_05/bin/javac - priority 100
    Current 'best' version is '/opt/jdk/jdk1.8.0_05/bin/javac'.

One more easy way for checking your installation is:

java -version

The output will look something like this:

 java version "1.8.0_05"
    Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

(Optional) Updating Java

For updating Java, an updated version can be downloaded from Oracle’s website and extracted under the /opt/jdk directory, which can then be set up as the default JVM having a higher priority number (in this case 110):

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

The old version can either be kept or deleted:

  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

The documented deployment procedure is confirmed to work upon a Debian server, but it can also be used with an Ubuntu server. Post a comment below in case any problem occurs even when all the steps are followed.

KB Admin has written 28 articles

Leave a Reply