net2020

Installing Open JDK on Linux from binaries

2/22/2014

Installing Open JDK on Linux from binaries

Introduction

Java is a programming language and a computing platform first released by Sun Microsystems in 1995. Oracle Corporation acquired Sun Microsystems in 2010. Since 2006 Oracle/Sun Microsystems began maintaining a free, open source implementation of the Java platform. This document explains how to install open source Java Development Kit on Debian Linux using JDK binary distribution.

Download JDK binaries

Open this link in new window: JDK download Click on the version you want to install. Click on Oracle Linux <version> x64 Java Development Kit and select Save File. I'm going to assume ~/Downloads as the default download directory.

Install JDK binaries

I like to install software in /opt folder. That requires root user access. You can always choose another directory. If you're using Gnome desktop you can open Root Terminal window. Check main menu under Applications / Accessories / Root Terminal. If you want to you can log in as root from a regular terminal window using su command. Open a terminal and press ENTER after each command:

cd /opt
mkdir jdk
cd jdk
mv /home/<user>/Downloads/openjdk-VERSION_linux-x64_bin.tar.gz .
tar xf openjdk-VERSION_linux-x64_bin.tar.gz
rm openjdk-VERSION_linux-x64_bin.tar.gz

That should create directory /opt/jdk-VERSION

I like to create a symlink pointing to the current JDK version called default. That way you can easily upgrade JDK installation without changing a lot of files:

cd /opt/jdk
ln -s jdk-VERSION default

Expose Java executables to all users

Again this requires root access. On Debian Linux systems directory /etc/alternatives contains links to all exposed binaries.

cd /etc/alternatives
ln -s /opt/jdk/default/bin/java
ln -s /opt/jdk/default/bin/javac

Then link all exposed binary files located in /etc/alternatives directory to /usr/local/bin:

cd /usr/local/bin
ln -s /etc/alternatives/java
ln -s /etc/alternatives/javac

You might also want to link jar, jconsole and keytool binaries.

Expose documentation

Manual (man) pages can be compressed or not. Look for those in /opt/jdk/default/man/man1 directory. Compressed manual for java runtime might be named java.1.gz, uncompressed could be named java.1. Again these steps require root access. First expose documentation files in /etc/alternatives directory:

cd /etc/alternatives
ln -s /opt/jdk/default/man/man1/java.1
ln -s /opt/jdk/default/man/man1/javac.1

Then link all exposed documentation files located in /etc/alternatives directory to /usr/share/man/man1:

cd /usr/share/man/man1
ln -s /etc/alternatives/java.1
ln -s /etc/alternatives/javac.1

You might also want to link documentation for jar, jconsole and keytool binaries.

These commands can be helpful when cleaning up symlinks. For listing JDK binaries in /etc/alternatives directory:

ls -al |grep jdk

For listing dangling symlinks in either /etc/alternatives or in /usr/share/man/man1:

find . -xtype l

Test Open JDK installation

At this point all your binaries and documentation should be available on your Linux system. To test java binary run this command from your home directory:

java -version

Expected output:

openjdk version "VERSION"
OpenJDK Runtime Environment (build VERSION)
OpenJDK 64-Bit Server VM (build VERSION, mixed mode)

To test documentation (man pages) run this command:

man java

You should see this and more:

NAME
       java - Launches a Java application.